my @nums = qw(2 1 3 5 4 5 4 3 2 1); # order is not important my @unique; # new list of unique elements my %seen; # numbers i have seen so far foreach my $x ( @nums ) { # check each number if ( ! $seen{$x} ) { # skip if we already saw this one $seen{$x} = 1; # note we have seen this one now push @unique, $x; # and store to new list } } ## TODO: do something with @unique