use strict; use warnings; my @array = ( 0 .. 50 ); for ( my $idx = 0; $idx <= $#array; $idx += 20 ) { my $top = $idx + 19; $top = ( $top <= $#array ) ? $top : $#array; print "Processing elements $idx through $top.\n"; foreach my $element ( @array[ $idx .. $top ] ) { # Process each $element here. ...for example... print $element, " "; } print "\n\tDone with $idx through $top.\n\n"; }