my @a = qw( a b c d e f g ); my $n = 3; my @b; for ( my $i = 0; $i <= $#a; $i += $n ) { push @b, [ @a[ $i .. $i+$n-1 ] ]; }