in reply to chomp - reference

You could chomp @$array outside the loop which has the same effect as the chomp inside the loop but makes it obvious that that is happening. $line is aliased to each element of @$array so the contents of @$array is altered by the loop in any case.

True laziness is hard work