Genesis 38:28-30
38:28 While she was giving birth, one child put out his hand, and the midwife took a scarlet thread and tied it on his hand, saying, “This one came out first.”
38:29 But then he drew back his hand, and his brother came out before him. She said, “How you have broken out of the womb!” So he was named Perez.
38:30 Afterward his brother came out – the one who had the scarlet thread on his hand – and he was named Zerah.