#!/usr/bin/perl use strict; use Data::Dumper; my %hash = ( abca => {comment => 'a_b__ca', para1 => 1, para2 => 2}, abcb => {comment => 'a_b__cb', para1 => 7, para2 => 2}, abcc => {comment => 'a_b__cc', para1 => 4, para2 => 2}, abcd => {comment => 'a_b__cd', para1 => 9, para2 => 2}, ); my %hash2; for (keys %hash) { my $tmp = $hash{$_}; $hash2{ $tmp->{'comment'} } = $tmp; $hash2{ $tmp->{'comment'} }->{'comment'} = $_; #delete $hash{$_}; } print Dumper %hash; print "-" x50; print Dumper %hash2;