foreach (@array) { if (! $hash{$_}) { $hash{$_} = $_; } else { ## duplicates output here or ignore print $_; } } # then print your hash to get your none duplicate results