in reply to Perl:how to find multiple strings
Also, the question is, are those variables supposed to be literal strings? If so, then you need to use quotemeta or \Q..\E to escape regular expression special characters:my $matches = grep {/1=$TAB_1/ && /5=$TAB_5/} @contents ;
And finally, if those strings are supposed to match in a particular order, then just put them back in a single regex with .* between them, not &&:my $matches = grep {/1=\Q$TAB_1\E/ && /5=\Q$TAB_5\E/} @contents ;
my $matches = grep {/1=\Q$TAB_1\E.*5=\Q$TAB_5\E/} @contents ;
|
|---|