Genesis 38:12-30 describes how the widower Judah impregnated his widowed daughter-in-law Tamar, who then gave birth to twins, Perez and Zerah. While this happens before Deut 23:2 is in place, it meant that once the Mosaic Law was established, the descendants of Perez and Zerah were forbidden from entering the Congregation until the tenth generation. Now look at the chronology provided in Ruth 4:18-22 (and supported by 1 Chronicles 2, Numbers 26, Genesis 46, etc.):
This, then, is the family line of Perez:Count 'em up. David is the tenth generation. That is, David is the first of his lineage to ever be able to enter the Congregation, since ten generations before him, the Mosaic Law wasn't even around. Now go back to Psalm 122:1, labeled "A Psalm of David": "I rejoiced when they said to me, 'Let us go to the house of the LORD.'" What a blessing that must have been, to be able to walk through the doors so long denied your family, and give thanks to God in His House. As beautiful as getting to worship God in congregation is, it was probably even more beautiful to David, who knew what an immense gift he had, since those before him didn't.
Perez was the father of Hezron,
Hezron the father of Ram,
Ram the father of Amminadab,
Amminadab the father of Nahshon,
Nahshon the father of Salmon,
Salmon the father of Boaz,
Boaz the father of Obed,
Obed the father of Jesse,
and Jesse the father of David.