There are many pssible ways you can think of.
You can try implementing char by char matching.
You can implement better methods for generating paragraphs.
Handle exceptional cases. The game does not work correctly if the paragraph has contiguous spaces.