$ cat test.pl use strict; use File::Basename; my @count = (); my @mask = ( '/some/path/', 'some/other/path', 'another/path', ); open F, "access.log"; while () { chomp; foreach my $m (@mask) { my $regex = "GET.*" . $m . ".*HTTP/1.1\" 200 [0-9].*"; if (/$regex/) { s/.*GET //; s/ HTTP.*//; my $bn = basename($_); my $found = 0; foreach (@count) { if ($_->[0] eq $bn) { $_->[1]++; $found = 1; last; } } if ($found == 0) { push @count, [ $bn, 1 ]; } } } } foreach (@count) { print "$_->[0] = $_->[1]\n"; } close F;