use List::Util 'reduce'; sub uniq { return @{;reduce {ref $a or $a=[$a]; push @$a, $b if $b ne $a->[-1]; $a} @_}; };