in reply to Searching and printing through a array
I can't reproduce your problem. Your code will print $line many times if more than one element of @all appears in $line. The following code eliminates the loop and replaces it with a single regular expression - maybe you can work from this example or show us data where this example doesn't do what you mean it should:
#!perl -wl use strict; my @all = qw( rsriram Corion ); my $re = sprintf '\b(?:%s)\b', join "|", map { quotemeta } @all; $re = qr/$re/; print "Searching for $re\n"; for (<DATA>) { chomp; if (/$re/) { print "Found at least one match in '$_'\n"; } else { print "Ignoring '$_'\n"; }; }; __DATA__ This is a line that mentions rsriram. This is a line that mentions Corion. This is a line that mentions Corion and rsriram together. This is a line that mentions neither of the two. This line intentionally left blank.
|
|---|