in reply to how do foreach and while affect an array?

Neither. Here is an idiom I occasionally use that does empty an array, though:
my $width = 4; my @in = "a".."z"; while (my @row = splice(@in, 0, $width)) { print "@row\n"; } __END__ Output: a b c d e f g h i j k l m n o p q r s t u v w x y z