in reply to Exact Match - GREP
In addition to using word boundaries, it looks like you should be reading your line into a scalar before checking against it. You may already be doing this but if so, it's not obvious from the one line you posted.
Here's a small snippet that works for me. I've included the contents of my test file in __DATA__.
#!/usr/bin/perl use strict; use warnings; use autodie; open my $fh, '<', '/path/to/your/file'; print "checking against <\$fh> once per \$Variable\n"; for my $Variable ( 'node', 'post', 'Perl' ) { print "$Variable match\n" if ( grep /\b$Variable\b/, <$fh> ); } seek($fh,0,0); # so we can start reading from the beginning again print "\nchecking against each line of <\$fh>\n"; while( my $line = <$fh> ) { for my $Variable ( 'node', 'post', 'Perl' ) { print "$Variable match\n" if ( grep /\b$Variable\b/, $line ); } } __DATA__ node _node post _post Perl _Perl Perl_ __END__ Output: checking against <$fh> once per $Variable node match checking against each line of <$fh> node match post match Perl match
|
|---|