Stumbled across this weird behavior today. Took a while to debug it. In the debugger, I'm not seeing the "dollar digit" regex capture variables set, even though the regex matches.
$ perl -de 1
Loading DB routines from perl5db.pl version 1.3
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
DB<1> ($foo) = ('abcd' =~
DB<2> x $1
DB<3> x $foo
Is this documented? I can't find it.
Update: Rafael explained it. The digit variables are lexically scoped. That's why you can assign to a package variable in a debugger, but not a lexical.
DB<6> 'abcd' =~
/(bc)/ && print $1