http://www.perlmonks.org?node_id=350058


in reply to Re: Re: Returning regexp pattern that was used to match
in thread Returning regexp pattern that was used to match

(?{ CODE }) will execute any perl code when the regex engine tries to match it. So for example:
my $string = "Bar"; $sting =~ /Foo(?{ print "Found a Foo\n" })|Bar(?{ print "Found a Bar\n +" })|Baz(?{ print "Found a Baz\n" })/;
Should print out 'Found a Bar'.

It's documented in the perlre man page under 'Extended Patterns'.