my @b = @{ reduce { push @$a, $b if !@$a || $b ne $a->[-1]; $a } [], @a };