# @seen is (I think) a pseudo-hash of common words @common = qw(a and at); # bigger in real life @seen{@common} = (); foreach $item (@words) { push(@only,$item) unless exists $seen{$item}; } @words = @only;