use strict; use warnings; my (@count, @patterns); push @patterns, qr /$_/ for qw/transaction find think save_param start_sub url submit/; # you could also write a slightly more Perlish: my @patterns = map { qr /$_/ } qw/transaction find think save_param start_sub url submit/; my $max = $#patterns; open my $FILEHANDLE, "<", "Action5.c" or die "cannot open < Action5.c: $!"; while (<$FILEHANDLE>) { for my $i (0..$max) { $count[$i]++ if $_ ~~ $patterns[$i]; } } for my $i (0..$max) { print "Number of patterns found for $patterns[$i] is $count[$i] \n"; } close $FILEHANDLE;