$line = " Jack and jill went up the hill to fetch a pail of water. Jack fell down and broke his crown and jill came tumbling after."; $newline = $line; ## MAKE A COPY OF THE LINE @wordlist = (hill,pail,water,down); # THE LIST OF WORDS TO SEARCH FOR ## FOR EACH WORD IN THE WORDLIST -- FOOTNOTE THE WORD for ($i=0; $i < @wordlist; $i++) { $currword = $wordlist[$i]; $newline =~ s/(\b$currword(?:ed|ing|al)?\b)/\\footnote\{$1 $hash{lc($1)}{explanation}\}/im; }