Update: Corrected the RE.

First thing to note: Use a hash for counting.
foreach (@count) { if ($_->[0] eq $bn) { $_->[1]++; $found = 1; last; } } if ($found == 0) { push @count, [ $bn, 1 ]; }
becomes
++$count{$bn};
Next thing: Precompile your RE and do it for all masks:
my $regex = join '|', @mask; # Now you have a list of alternatives $regex = qr<GET (.*\b(?:$regex)\b.*) HTTP/1.1" 200 [0-9].*>; # now the regex is precompiled
(Untested!)

Next thing: Why not replace while searchin. So
if (/$regex/) { s/.*GET //; s/ HTTP.*//; : :
is reduced to
if (s/$regex/$1/) { : :
Putting it all together and eliminating the unneccessary replace and chomp will give you this script, that should (UNTESTED) give the same result as yours, except for the sequence of filenames which will be sorted:
use strict; use File::Basename; my %count; my @mask = ( '/some/path/', 'some/other/path', 'another/path', ); my $regex = join '|', @mask; # Now you have a list of alternatives $regex = qr<GET (.*\b(?:$regex)\ +b.*) HTTP/1.1" 200 [0-9].*> # now the regex is precompiled # N.B. I added \b to make the filename only match on word boundaries. # So some/path won't match anothersome/path # but it will match another/some/path open F, "access.log"; while (<F>) { if (/$regex/) { ++$count{basename($1)}; } } foreach (sort keys %count) { print $_," = ",$count{$_},"\n"; }

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

In reply to Re: log parsing very slow by Skeeve
in thread log parsing very slow by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.