in reply to grep match variable position

Just my two cents here,
for each $word why dont you create a custom regex array instead of just a stopword array? You might like reading this regarding the proper storage of your regexes.
your standard regex could look like something like this:

#!/usr/bin/perl my $string = $ARGV[0]; if($string =~ m#(\Aof|of\z)#){ print "matched out at start or end\n"; }
tested on my machine.