If you have a few regex to apply to each line an array of pre-compiled regex is about the most optimimum you are going to get if you need to know which regex matched. If you only care about the fact one did match you could construct one super regex to rule them all but that could be dificult.
#!/usr/bin/perl
use strict;
use warnings;
my @regex;
while (<DATA>) {
chomp;
push @regex, qr/$_/;
}
while (my $line = <STDIN>) {
for (0..$#regex) {
print "matched no: $_\n" if $line=~/$regex[$_]/;
}
}
__DATA__
foo
bar
baz
Cheers,
R.
Pereant, qui ante nos nostra dixerunt!