while(<>){ for my $pat ( qr/\d/, qr/string/ ){ my $count = () = /$pat/g; print "$pat matched $count times\n"; } }