@array = sort @array; my $j = 0; my $last; for my $e (@array) { if (!$j or $last ne $e) { $array[$j] = $last = $e; $j++; } } $#array = $j-1;