Then Judah said to Er's brother Onan, "You must marry Tamar, as our law requires of the brother of a man who has died. Her first son from you will be your brother's heir."
But Onan was not willing to have a child who would not be his own heir. So whenever he had intercourse with Tamar, he spilled the semen on the ground to keep her from having a baby who would belong to his brother.
Then Judah told Tamar, his daughter-in-law, not to marry again at that time but to return to her parents' home. She was to remain a widow until his youngest son, Shelah, was old enough to marry her. (But Judah didn't really intend to do this because he was afraid Shelah would also die, like his two brothers.) So Tamar went home to her parents.
In the course of time Judah's wife died. After the time of mourning was over, Judah and his friend Hirah the Adullamite went to Timnah to supervise the shearing of his sheep.
Tamar was aware that Shelah had grown up, but they had not called her to come and marry him. So she changed out of her widow's clothing and covered herself with a veil to disguise herself. Then she sat beside the road at the entrance to the village of Enaim, which is on the way to Timnah.
"Well, what do you want?" he inquired. She replied, "I want your identification seal, your cord, and the walking stick you are carrying." So Judah gave these items to her. She then let him sleep with her, and she became pregnant.
Judah asked his friend Hirah the Adullamite to take the young goat back to her and to pick up the pledges he had given her, but Hirah couldn't find her.
So he asked the men who lived there, "Where can I find the prostitute who was sitting beside the road at the entrance to the village?We've never had a prostitute here," they replied.
So Hirah returned to Judah and told him that he couldn't find her anywhere and that the men of the village had claimed they didn't have a prostitute there.
"Then let her keep the pledges!" Judah exclaimed. "We tried our best to send her the goat. We'd be the laughingstock of the village if we went back again."
About three months later, word reached Judah that Tamar, his daughter-in-law, was pregnant as a result of prostitution. "Bring her out and burn her!" Judah shouted.
But as they were taking her out to kill her, she sent this message to her father-in-law: "The man who owns this identification seal and walking stick is the father of my child. Do you recognize them?"
Judah admitted that they were his and said, "She is more in the right than I am, because I didn't keep my promise to let her marry my son Shelah." But Judah never slept with Tamar again.
As they were being born, one of them reached out his hand, and the midwife tied a scarlet thread around the wrist of the child who appeared first, saying, "This one came out first."
But then he drew back his hand, and the other baby was actually the first to be born. "What!" the midwife exclaimed. "How did you break out first?" And ever after, he was called Perez.