use warnings; use strict; my @pats = qw(ab ac ad ba bla etc); my %pos; @pos{ @pats } = 1 .. @pats; my $re = join '|', @pats; $re = qr/$re/; while (<DATA>) { print "$1 $pos{$1}\n" if /($re)/; } __DATA__ fable fact
Output:
ab 1 ac 2
In reply to Re: position number
by toolic
in thread position number
by mrc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |