This question already has an answer here:
- How old were Er and Onan when they died? 2 answers
וַיְהִי בָּעֵת הַהִוא וַיֵּרֶד יְהוּדָה מֵאֵת אֶחָיו וַיֵּט עַד-אִישׁ עֲדֻלָּמִי וּשְׁמוֹ חִירָה.
וַתָּסַר בִּגְדֵי אַלְמְנוּתָהּ מֵעָלֶיהָ וַתְּכַס בַּצָּעִיף וַתִּתְעַלָּף וַתֵּשֶׁב בְּפֶתַח עֵינַיִם אֲשֶׁר עַל-דֶּרֶךְ תִּמְנָתָה כִּי רָאֲתָה כִּי-גָדַל שֵׁלָה וְהִוא לֹא-נִתְּנָה לוֹ לְאִשָּׁה.
וּבְנֵי יְהוּדָה עֵר וְאוֹנָן וְשֵׁלָה וָפֶרֶץ וָזָרַח וַיָּמָת עֵר וְאוֹנָן בְּאֶרֶץ כְּנַעַן וַיִּהְיוּ בְנֵי-פֶרֶץ חֶצְרֹן וְחָמוּל.
The math here simply doesn't work out. We know the following:
- Yehuda "descended" from his brothers after the sale of Yosef.
- For his eldest son Er to marry Tamar, he must have been at least 13 years old. Which means this marriage happened at least about 14 years after the sale of Yosef
- Shelah was too young to perform yibum at the time of Onan's death, i.e. under 9 years old. There was some period of waiting before Tamar decided to seduce Yehuda, and thereby become pregnant. Therefore we could estimate aggressively that Peretz was born a year later, i.e. 15 years after the sale of Yosef.
- 22 years elapsed between the sale of Yosef and the family of Israel coming down to Egypt. Therefore Peretz would have been at most 7 years old, maybe 8 if you really push the envelope.
And yet - he had two sons at the time?!
Meam Loez notes this apparent difficulty:
No apologetics there; apparently the author was comfortable with the concept of a seven-year-old being able to sire children.
I have not found any other sources that deal with this question. I'm hoping for something of a somewhat more rationalist bent. The only idea I came up with on my own is that maybe Yehuda actually married Bat-Shua before the sale of Yosef, but the story is recorded here as part of Yehuda's "descent", starting with the sale of Yosef. Any sources that support me on this? Or other sources with a different explanation?