my @in = qw(test foo test bar baz foo test); my %keycount; foreach (@in) { $keycount{$_}++; # do whatever else you need to do } foreach (keys %keycount) { #print $_ if $keycount > 1; print if $keycount{$_} > 1; # Thx, ++Aristotle! # or do something else with $_ }