in reply to creating and printing a sliding window

I would stick with the while loop as it is more scalable and make use of List::Util.
use warnings; use strict; use List::Util qw(max); my @window; while (<DATA>) { chomp(); # create sliding window push(@window, [ (split) ]); shift(@window) if $. > 5; # print range print $window[0][0], "-", $window[-1][0]; # print maximums for my $i (1 .. 5) { print " ", max(map { $_->[$i] } @window); } print "\n"; } __END__ 1 0 0.00 0 0 0 2 0 0.00 0 0 0 3 0 0.08 0 0 0 4 0 0.05 0 0 0 5 0 0.08 0 0 0 6 0 0.05 0 0.12 0 7 0 0.05 0 0.12 0 8 0 0.04 0 0.15 0 9 0.07 0.07 0 0.15 0.18 10 0.29 0.04 0.32 0.32 0.19 11 0.46 0.05 0.42 0.30 0.21 12 0.45 0.07 0.35 0.29 0.41 13 0.57 0.07 0.42 0.00 0.47 14 0.46 0.04 0.62 0.00 0.58 15 0.39 0.05 0.41 0.00 0.37

Output:
1-1 0 0.00 0 0 0 1-2 0 0.00 0 0 0 1-3 0 0.08 0 0 0 1-4 0 0.08 0 0 0 1-5 0 0.08 0 0 0 2-6 0 0.08 0 0.12 0 3-7 0 0.08 0 0.12 0 4-8 0 0.08 0 0.15 0 5-9 0.07 0.08 0 0.15 0.18 6-10 0.29 0.07 0.32 0.32 0.19 7-11 0.46 0.07 0.42 0.32 0.21 8-12 0.46 0.07 0.42 0.32 0.41 9-13 0.57 0.07 0.42 0.32 0.47 10-14 0.57 0.07 0.62 0.32 0.58 11-15 0.57 0.07 0.62 0.30 0.58