foreach my $line (@htmlLines) { if(/$pattern1 && $pattern2/) { printHTML(); } else { notFound(); } }