my @b = list_reduce { undef, !@$_ || $b ne $_->[-1] ? $b : () } undef, @a; my @b = list_reduce { 0, !@$_ || $b ne $_->[-1] ? $b : () } 1, @a; my @b = list_reduce { $b, defined($b) && $b ne $a ? $b : () } undef, @a; my @b = list_reduce { $b, grep defined && $_ ne $a, $b } undef, @a;