sub groups_of_n { my $n = shift; return map { [ grep {defined} @$_ ] } map { [ @_ [$_ * $n .. $_ * $n + $n -1 ]] } 0 .. $#_ / $n; }