#!/usr/bin/perl -w use strict; my $maxLen = 0; my $aline = qq~an interesting line of text I would like to scan I see I see I see~; my @regexes = (['first',qr/should fail/,0] , ['second','like',0] , ['third',qr/I/,0] , ['fourth',qr/scan/,0]); sub niceOutput {for(@regexes){ printf "%-${main::maxLen}s %30d\n", $_->[1],$_->[2] if $_->[2] > 0} } sub resetRegexes {for(@regexes){$_->[2] = 0}} sub rexyScan {my $Len = 0; for my $n(@regexes){ ++$n->[2] while ($aline=~m/$n->[1]/g); $Len = length $n->[1]; if($Len > $maxLen) { $main::maxLen = $Len } }; } &rexyScan; &niceOutput;