After the Magi had visited the infant Jesus, Matthew writes, “When they had departed, behold, the angel of the Lord appeared to Joseph in a dream and said, ‘Rise, take the Child and His mother, flee to Egypt, and stay there until I tell you. Herod is going to search for the Child to destroy Him.’ Joseph rose and took the Child and His mother by night and departed for Egypt.” Mt 2:13-14
In Luke we read, “When the days were completed for their purification according to the law of Moses, they took Him up to Jerusalem to present Him to the Lord,” Lk 2:22 We assume this to mean that it took place 40 days after His birth.
Then a few verses later we read, “When they had fulfilled all the prescriptions of the law of the Lord, they returned to Galilee, to their own town of Nazareth.” Lk 2:39
How does one rectify these two different accounts? I have read/heard these accounts for many years and have never connected (or unconnected) the two. Should these two stories be read in isolation of one another?