in reply to Regex: return the pattern instead of the actual match

This only works if there are no capturing parenthesis:

#!/usr/bin/perl use v5.12; use warnings; use strict; my @alt = ( qr/foo\d+/, qr/bar\S+?/, ); my $re = join '|', map qr/($_)/, @alt; for my $word (qw[foofoo2010 subarashii bowwowmeow]) { my $_ = $word; if (s/$re/($+)/) { say "$word => $_: $alt[$#- - 1]"; } else { say "$word: NO_MATCH"; } }

This is the output:

foofoo2010 => foo(foo2010): (?-xism:foo\d+) subarashii => su(bara)shii: (?-xism:bar\S+?) bowwowmeow: NO_MATCH