for (my $i = 0; $i <= $#list; $i += $C) { my $end = $i + $C - 1; $end = $#list if $end > $#list; push @AoA, [ @list[$i .. $end] ]; }