sub group (@array is copy) { # didn't flatten gather { while @array { take [ gather { my $h = shift @array; take $h; while @array and $h eq @array[0] { take shift @array; } } ]; } } }