in reply to how to use reversehash if there are more than one keys same

Assuming the keys of your input hash cannot contain the '|' character. Straight forward:
sub reversehash { my $href = shift; my %h; for (keys %$href) { my $v = $href->{$_}; if (exists $h{$v}) { $h{$v} .= "|$_"; } else { $h{$v} = $_; } } return \%h; }
To impress the chicks:
sub reversehash { my %h; push @{$h{$_[0]->{$_}}}, $_ for keys %{$_[0]}; $h{$_} = join '|', @{$h{$_}} for keys %h; return \%h; }