Judah and Tamar 1
About this time, Judah left home and moved to Adullam, where he stayed with a man named Hirah.
There he saw a Canaanite woman, the daughter of Shua, and he married her. When he slept with her,
she became pregnant and gave birth to a son, and he named the boy Er.
Then she became pregnant again and gave birth to another son, and she named him Onan.
And when she gave birth to a third son, she named him Shelah. At the time of Shelah's birth, they were living at Kezib.
In the course of time, Judah arranged for his firstborn son, Er, to marry a young woman named Tamar.
But Er was a wicked man in the LORD's sight, so the LORD took his life.
Then Judah said to Er's brother Onan, "Go and marry Tamar, as our law requires of the brother of a man who has died. You must produce an heir for your brother."
But Onan was not willing to have a child who would not be his own heir. So whenever he had intercourse with his brother's wife, he spilled the semen on the ground. This prevented her from having a child who would belong to his brother.
But the LORD considered it evil for Onan to deny a child to his dead brother. So the LORD took Onan's life, too.
Then Judah said to Tamar, his daughter-in-law, "Go back to your parents' home and remain a widow until my son Shelah is old enough to marry you." (But Judah didn't really intend to do this because he was afraid Shelah would also die, like his two brothers.) So Tamar went back to live in her father's home.
Some years later Judah's wife died. After the time of mourning was over, Judah and his friend Hirah the Adullamite went up to Timnah to supervise the shearing of his sheep.
Someone told Tamar, "Look, your father-in-law is going up to Timnah to shear his sheep."
Tamar was aware that Shelah had grown up, but no arrangements had been made for 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 road to Timnah.
Judah noticed her and thought she was a prostitute, since she had covered her face.
So he stopped and propositioned her. "Let me have sex with you," he said, not realizing that she was his own daughter-in-law.
"How much will you pay to have sex with me?" Tamar asked.
"I'll send you a young goat from my flock," Judah promised.
"But what will you give me to guarantee that you will send the goat?" she asked.
"What kind of guarantee do you want?" he replied.
She answered, "Leave me your identification seal and its cord and the walking stick you are carrying." So Judah gave them to her. Then he had intercourse with her, and she became pregnant.
Afterward she went back home, took off her veil, and put on her widow's clothing as usual.
Later Judah asked his friend Hirah the Adullamite to take the young goat to the woman and to pick up the things he had given her as his guarantee. But Hirah couldn't find her.
So he asked the men who lived there, "Where can I find the shrine prostitute who was sitting beside the road at the entrance to Enaim?"
"We've never had a shrine prostitute here," they replied.
So Hirah returned to Judah and told him, "I couldn't find her anywhere, and the men of the village claim they've never had a shrine prostitute there."
"Then let her keep the things I gave her," Judah said. "I sent the young goat as we agreed, but you couldn't find her. We'd be the laughingstock of the village if we went back again to look for her."
About three months later, Judah was told, "Tamar, your daughter-in-law, has acted like a prostitute. And now, because of this, she's pregnant."
"Bring her out, and let her be burned!" Judah demanded.
But as they were taking her out to kill her, she sent this message to her father-in-law: "The man who owns these things made me pregnant. Look closely. Whose seal and cord and walking stick are these?"
Judah recognized them immediately and said, "She is more righteous than I am, because I didn't arrange for her to marry my son Shelah." And Judah never slept with Tamar again.
When the time came for Tamar to give birth, it was discovered that she was carrying twins.
While she was in labor, one of the babies reached out his hand. The midwife grabbed it and tied a scarlet string around the child's wrist, announcing, "This one came out first."
But then he pulled back his hand, and out came his brother! "What!" the midwife exclaimed. "How did you break out first?" So he was named Perez. 
Then the baby with the scarlet string on his wrist was born, and he was named Zerah.