my $pat_id; my $pat1 = qr/field(?{$pat_id=1})/; my $pat2 = qr/f.i.e.l.d(?{$pat_id=2})/; my $pat3 = qr/the(?{$pat_id=3})/; my $str = "There are many soccer fields in England - f1i2e3l4d"; while ( $str =~ m/($pat1|$pat2|$pat3)/ig ) { print "Found '$1' from pattern pat", $pat_id, "\n"; }