in reply to Determining which pattern matched

My variation of the named captures theme:

#! perl -slw use strict; my $pat1 = "field"; my $pat2 = "f.i.e.l.d"; my $pat3 = "the"; my $str = "There are many soccer fields in England - f1i2e3l4d"; while( $str =~ m/((?'A'$pat1)|(?'B'$pat2)|(?'C'$pat3))/ig ){ printf "Found '$1' from pattern '%s'\n", grep{ defined $-{ $_ }[ 0 ]; } keys %-; } __END__ C:\test>junk Found 'The' from pattern 'C' Found 'field' from pattern 'A' Found 'f1i2e3l4d' from pattern 'B'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"