in reply to Matching multiple patterns with regex
You're basically looking for "From" and "Subject" on the same line, which usually does not occur in emails. Change your logical and to a logical or, and you'll match lines having "From" and lines having "Subject".
In other words, try to change:
To something like:while (my $line = <$fh>){ if ($line =~ /From\:/ && $line =~ /Subject\:/) { print $line; } }
Update: And since, as mentioned above by ww above, there is no need to escape colons, you could simplify it this way:while (my $line = <$fh>){ if ($line =~ /From\:/ or $line =~ /Subject\:/) { print $line; } }
while (my $line = <$fh>){ if ($line =~ /From:/ or $line =~ /Subject:/) { print $line; } }
|
|---|