use strict; use warnings; my %hash = (a => 1, b => 2, c => 1, d => 3, e => 5); my @non_unique = duplicated_values_keys(%hash); print "$_\n" for @non_unique; sub duplicated_values_keys { my %hash = @_; my %inverted; push @{$inverted{$hash{$_}}}, $_ for keys %hash; return map {@{$inverted{$_}} > 1 ? @{$inverted{$_}} : ()} keys %inverted; }