#! perl -sw use strict; { my $next=0; sub elements(\@$) { my ($ref, $count) = @_; my $max = $#$ref; $next=0, return if $next > $max; my $first = $next; my $last = $next+$count-1; $last = $max if $max < $last; $next += $count; @{$ref}[$first .. $last]; } } my @letters = ('a'..'z'); while(my @els = elements(@letters, 5) ) { print "@els\n"; } __END__ 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