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


in reply to Test::More not working with Perl local special variables

It's a dynamic scoping issue:

>perl -wMstrict -le "my $s = 'foobar'; printf qq{\$& in sub: '%s' \n}, S($s); print qq{\$& post sub: '$&'}; print '$& undefined' unless defined $&; ;; sub S { $_[0] =~ m{ oob }xms; return $&; } " $& in sub: 'oob' Use of uninitialized value $& in concatenation (.) or string at ... $& post sub: '' $& undefined

See the section Variables related to regular expressions in perlvar: "These variables are read-only and dynamically-scoped, unless we note otherwise."