#!/usr/bin/perl -wT use strict; my @a = (1..16); # test array my $atatime = 3; # number of elements to loop over for my $i (0..$#a/$atatime) { # loop through @a/$atatime times my $min = $i*$atatime; # index of low element my $max = $min+$atatime-1; # index of high element $max = $#a if $max > $#a; # make sure we don't fall off the end print join(", ", @a[$min..$max]),"\n"; # do something with our slice } # Verify that we haven't munged our values print "\nStill There: ", join(' ',@a), "\n"; =output 1, 2, 3 4, 5, 6 7, 8, 9 10, 11, 12 13, 14, 15 16 Still There: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16