Genesis 38:1-30 NIV
At that time, Judah left his brothers and went down to stay with a man of Adullam named Hirah. There Judah met the daughter of a Canaanite man named Shua. He married her and made love to her; she became pregnant and gave birth to a son, who was named Er. She conceived again and gave birth to a son and named him Onan. She gave birth to still another son and named him Shelah. It was at Kezib that she gave birth to him.
Judah got a wife for Er, his firstborn, and her name was Tamar. But Er, Judah’s firstborn, was wicked in the LORD’s sight; so the LORD put him to death.
Then Judah said to Onan, “Sleep with your brother’s wife and fulfill your duty to her as a brother-in-law to raise up offspring for your brother.” But Onan knew that the child would not be his; so whenever he slept with his brother’s wife, he spilled his semen on the ground to keep from providing offspring for his brother. What he did was wicked in the LORD’s sight; so the LORD put him to death also.
Judah then said to his daughter-in-law Tamar, “Live as a widow in your father’s household until my son Shelah grows up.” For he thought, “He may die too, just like his brothers.” So Tamar went to live in her father’s household.
After a long time Judah’s wife, the daughter of Shua, died. When Judah had recovered from his grief, he went up to Timnah, to the men who were shearing his sheep, and his friend Hirah the Adullamite went with him.
When Tamar was told, “Your father-in-law is on his way to Timnah to shear his sheep,” she took off her widow’s clothes, covered herself with a veil to disguise herself, and then sat down at the entrance to Enaim, which is on the road to Timnah. For she saw that, though Shelah had now grown up, she had not been given to him as his wife.
When Judah saw her, he thought she was a prostitute, for she had covered her face. Not realizing that she was his daughter-in-law, he went over to her by the roadside and said, “Come now, let me sleep with you.”
“And what will you give me to sleep with you?” she asked.
“I’ll send you a young goat from my flock,” he said.
“Will you give me something as a pledge until you send it?” she asked.
He said, “What pledge should I give you?”
“Your seal and its cord, and the staff in your hand,” she answered. So he gave them to her and slept with her, and she became pregnant by him. After she left, she took off her veil and put on her widow’s clothes again.
Meanwhile Judah sent the young goat by his friend the Adullamite in order to get his pledge back from the woman, but he did not find her. He asked the men who lived there, “Where is the shrine prostitute who was beside the road at Enaim?”
“There hasn’t been any shrine prostitute here,” they said.
So he went back to Judah and said, “I didn’t find her. Besides, the men who lived there said, ‘There hasn’t been any shrine prostitute here.’ ”
Then Judah said, “Let her keep what she has, or we will become a laughingstock. After all, I did send her this young goat, but you didn’t find her.”
About three months later Judah was told, “Your daughter-in-law Tamar is guilty of prostitution, and as a result she is now pregnant.”
Judah said, “Bring her out and have her burned to death!”
As she was being brought out, she sent a message to her father-in-law. “I am pregnant by the man who owns these,” she said. And she added, “See if you recognize whose seal and cord and staff these are.”
Judah recognized them and said, “She is more righteous than I, since I wouldn’t give her to my son Shelah.” And he did not sleep with her again.
When the time came for her to give birth, there were twin boys in her womb. As she was giving birth, one of them put out his hand; so the midwife took a scarlet thread and tied it on his wrist and said, “This one came out first.” But when he drew back his hand, his brother came out, and she said, “So this is how you have broken out!” And he was named Perez. Then his brother, who had the scarlet thread on his wrist, came out. And he was named Zerah.
NIV: New International Version