http://www.perlmonks.org?node_id=1064246


in reply to Match 2 strings in same line

The problem with your code is that you are not binding the second match to $line, so it implicitly binds to $_, which isn't what you want. The simplest change would be this:

push @eigrp, "$line\n" if $line =~ m/$logsIncDate/ && $line =~ m/SW_MATM-4-MACFLAP_NOTIF/;

Also, if you're just going to be appending a newline to your output, maybe (I don't know because I haven't seen the bigger picture) you could avoid that need by not chomping your input. And if your while loop is trivial, you could use implicit "$_":

while( <$fh> ) { push @eigrp, $_ if /$logsIncDate/ && /SW_MATM-4-MACFLAP-NOTIF/; }

Dave