In Bereshis 38:28 Zerach puts his hand outside the womb first and the midwife ties a string on it saying "this one came out first". However in Bechoros 8:1 (46a, et passim) it indicates that only putting the head or the majority of the body is enough to achieve Bechor status.
I realize that the pasuk doesn't necessarily have to be resolved with the gemarah, one could explain the discrepancy by saying that the midwife was ignorant of the halacha (assuming the tribes abided by some sense of halacha before the Torah was given).
However, it does appear that Peretz is treated as the Bechor In which case there should be a reason that the Torah tells us what the midwife did. I am curious if any commentaries address and explain this.