my @regexes = map qr{GET (.*$_.*) HTTP/1.1" 200 [0-9]}, @mask; #### my (%count, @order); while () { chomp; for my $rx (@regexes) { if (/$rx/) { my $bn = basename($1); $count{$bn}++ or push @order, $bn; } } } #### my $alts = join '|', map quotemeta, @masks; my $rx = qr{GET (.*(?:$alts).*) HTTP/1.1" 200 [0-9]}; my (%count, @order); while () { chomp; if (/$rx/) { my $bn = basename($1); $count{$bn}++ or push @order, $bn; } }