Designing the code
Two ways to analyze the document text and match a query:
- Split the text into an array of "words" and compare each word against the query. Faster but less accurate. Phrase searches require complex look-ahead/behind gymnastics.
- Build a regular expression based on the query and let Perl analyze the text for you. Slower but more accurate. And fewer gymnastics (for the less limber).