while (scalar @data) { for (1 .. 100) { formatted_print(shift @data) if scalar @data; } # Do whatever else between runs of 100 } sub formatted_print { my $line_arrayref = shift; # Print the line in whatever format you want }