in reply to assignment to scalar changing array content

Inside foreach loops, the iterator variable is actually an alias for the element in the array, and if you change it it will change the contents of the array. From perlsyn(1):

Foreach Loops

If any element of LIST is an lvalue, you can modify it by modifying VAR inside the loop. Conversely, if any element of LIST is NOT an lvalue, any attempt to modify that element will fail. In other words, the "foreach" loop index variable is an implicit alias for each item in the list that you're looping over.

You can work around this by just copying the loop variable into a normal scalar variable:

foreach $loop_ralias (@{$refarrayptr}) { my $ralias = $loop_ralias; # ... }