use Data::Dumper; my @array; for my $i ( 0 .. 63 ) { push @array, [] if $i % 8 == 0; push @{$array[-1]}, $i; } print Dumper \@array;