http://www.perlmonks.org?node_id=1039229
raygun has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise monks,

I'm unsure why these two lines produce different output. In particular, I don't know why the ${^MATCH} in the first line fails to be set to the matched part of the regular expression.
perl -e '$x = "abcde"; $x =~ s/b../==${^MATCH}==/p; print + "$x\n"' perl -e '$x = "abcde"; $sub="b.."; $x =~ s/$sub/==${^MATCH}==/p; print + "$x\n"'
Perl v5.12.4 produces:
a====e a==bcd==e
The perlre documentation gives no restrictions on contexts in which {^MATCH} can be used, saying only that it's an optimized synonym for $&. And in fact, if I change the first line to use $& instead of {^MATCH}, it behaves as expected. Thank you for any hints!