in reply to Strange modification of @_

The use of @_ is a red herring here.   The same problem can be demonstated with this one-liner:

$ perl -Mwarnings -le' $_ = "x"; s/(x)/ my $str = $1; print "$1"; $str + =~ s<x><>; print "$1"; /e; ' x Use of uninitialized value in string at -e line 1.

The problem is that the second substitution, even though in a subroutine, clears the $1 variable.