sub split_to_n { my @buckets = map {[]} 1..shift; while (@_) { my $b = shift @buckets; push @$b, shift; push @buckets, $b; } @buckets; }