#!/usr/bin/perl use strict; my @input = qw(a b c d e d e f); # %seen is a hash used to count the number of times # an element appears in the array. @result contains # the results of removing the duplicates. my (%seen, @result); foreach (@input) { $seen{$_}++; } foreach (@input) { # Snag the elements which appear only once. # Use the original elements of the input array # as hash keys rather than keys(%seen) to # preserve ordering if ($seen{$_} == 1) { push @result, $_; } }