my %hash = ( a => 1, b => 2, c => 3 ); my %inverted_hash = reverse %hash; #### use Data::Dumper; print Dumper(\(%hash, %inverted_hash)); # Output: # $VAR1 = { # 'c' => 3, # 'a' => 1, # 'b' => 2 # }; # $VAR2 = { # '1' => 'a', # '3' => 'c', # '2' => 'b' # }; #### %hash = ( a => 1, b => 2, c => 2 ); %inverted_hash = reverse %hash; print Dumper(\(%hash, %inverted_hash)); # Output: # $VAR1 = { # 'c' => 2, # 'a' => 1, # 'b' => 2 # }; # $VAR2 = { # '1' => 'a', # '2' => 'c' # }; #### print "keys were lost during inversion\n" if keys %inverted_hash < keys %hash;