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


in reply to Precise backreference semantics in Perl regular expressions

Seems weird. And what really smells suspicious is that if you switch the order of the alternatives, the second string suddenly matches the regex.
for my $regexp (qr/^((a*)b|a*b?d)*c\2$/, qr/^(a*b?d|(a*)b)*c\2$/) { for my $string (qw( aabadcaa aababdcaa )) { say $string =~ /$regexp/ ? 'Yes' : 'No'; } }
Output:
Yes No Yes Yes

If you want to know what Perl's regex engine does, not just guess, run the script with

use re 'debug';

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]