Roll the inner three checks into a loop. So you have
my @patterns = (qr/(patternOne)/, qr/(patternTwo)/);
my $match;
print "PAGE ->\t$name\ndata ->";
for my $pat (@patterns) {
if ($line =~ $pat and not $match++) {
print "\t\t$1\nMATCHED - >\t$hit\n";
push (@files, $name);
$ct++;
last;
}
}
$print " TEXT INFO HERE.\n" if not $match;
Mmmmm refactoring. See also Once and Only Once.
Update: Fixed bugs pointed out by Re: Re: Shorten script. Big error, thanks for the heads-up. Hrm. Could probably still be cleaned up more.. let's call that an exercise to the reader..
Update: stole idea (break up prints) from sauoq's response. If you are unlikely to add more conditions, his way is probably better. Mine is pretty easy to add new conditions to though, just add to the @patterns = (...);