Another interpretation of (Genesis 39:1) "And Joseph was brought down to Egypt, etc." What is written above on this matter? (Genesis 38:29) "And it came to pass, as he drew back his hand, [and his name was called Perez]" — this is kingship, (Ruth 4:18) "And these are the generations of Perez." And afterward (Genesis 38:30) "his brother came out" — this is priesthood. And afterward, "And Joseph was brought down to Egypt." But the Holy One, blessed be He, brought them good tidings that in every place where they go they make use of a king and a priest. How so? In Egypt, by a king and a priest, as it is said (Exodus 7:8), "And the LORD said to Moses and to Aaron, etc." And at their going out, (Psalms 77:21) "You led Your people like a flock by the hand of Moses and Aaron."
Perez Zerah and Joseph as Sign of King and Priest in Egypt
Midrash Tanchuma Buber, Vayeshev 21:1
ד"א ויוסף הורד מצרימה וגו'. מה כתיב למעלה מן הענין, ויהי כמשיב ידו [ויקרא שמו פרץ] (בראשית לח כט), זה מלכות, ואלה תולדות פרץ (רות ד יח). ואחר כך יצא אחיו (בראשית שם) זה כהן, ואחר כך ויוסף הורד מצרימה, אלא שבישרן הקב"ה שכל מקום שהן הולכין הן משתמשין במלך וכהן, כיצד במצרים במלך וכהן, שנאמר ויאמר ה' אל משה ואל אהרן וגו' (שמות ז ח). וביציאתם נחית כצאן עמך ביד משה ואהרן (תהלים עז כא).