in reply to question about the function "my"

The my causes a new lexical variable @stuff to be created each iteration of the while loop. Thus each element of @lines is a reference to a different array.

By contrast, without the my, @stuff is an ordinary global variable. Each iteration assigns it different values, but it is the same array, with the same reference each time around. Thus all the elements of @lines would point to the same array and you would naturally get the last values assigned to that array.

-Mark