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