@out = grep $sd[$_] ne $sd[1+$_], 0 .. $#sd; #### my $prev; @out = grep "$prev" ne ($prev = $_), sort @sd; # not for production code