sub divarray { my @a = @{shift @_}; my @b = @{shift @_}; my @c; my $b = int(@a/@b)+1; while ( @a ) { push @c, [splice (@a, 0, $b)]; } return \@c; }