or download this
my @b = list_reduce { push @$_, $b if !@$_ || $b ne $_->[-1]; undef }
+undef, @a;
...
my @b = list_reduce { push @$_, $b if defined($b) && $b ne $a; $b } un
+def, @a;
my @b = list_reduce { push @$_, grep defined && $_ ne $a, $b; $b } und
+ef, @a;