in reply to position number

You might want something like:
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