use strict; use warnings; my @array = (1,2,5,6,4,2,1,2,3,4,6,4,3,2,4,6,6); my @sorted = sort {$a <=> $b} @array; # numerically @array = (sort shift @sorted); # overwrite old array while (my $element = shift @sorted) { # if the element differs from the last added, keep it # otherwise discard if ($element != $array[-1]) { push (@array, $element); } } # array is now sorted, no duplicate elements