Even though I don't understand what "for my $i (0 .. $#arr)"
$#array is the index of the last element of @array. Which is the same as the scalar(@array)-1;
a subroutine can change variables from the function it was called from
Yes, if you modify @_, it changes for the caller.