in reply to Re: Matching problem
in thread Matching problem

Rather than making two copies of the full file content in memory (and wasting cycles on a useless join), it would be better either to slurp the whole file into a scalar, like this:
{ local $/ = undef; open(FILE,$filename) or die "open failed on $filename: $!"; $wholetext = <FILE>; close FILE; } if ( $wholetext =~ /\b$searchword\b/ ) { # do something }
Or to read the file into an array and use grep on the array, like this:
open( FILE, $filename ) or die "yadda yadda"; @data = <FILE>; if ( grep /\b$searchword\b/, @data ) { # do something; }