That is doubly confusing code ...
2 effects are overlaying.
- the @arr inside the sub is the same like outside, because you didn't use my again. (Change the name and strict will throw an error, otherwise the function is a closure)
- the elements of @_ are aliases of the elements passed, i.e. the values of @arr
(like demonstrated by Tobyink)
Since you reassign these elements with the map, you are effectively changing @_, it's like writing @_ = map { 2 * $_ } @_;
Change this to my @arr = map { 2 * $_ } @_; and your problem disappears
Style tips how to avoid this
it's always a good strategy to choose meaningful names for variables instead of arr or array , like this strict would have caught the error.
don't declare variables on top of your program if you only intend to use them much later.