in reply to inner anonymous hash

Since $key can be duplicate, it might make sense to have it point to an array that you can push records onto. For example:

push @{$hash{$key}}, { $valname => [ $value, $type, $flag ] };

You could then cycle over the structure like this:

foreach my $i(keys %hash) { print "i=$i\n"; foreach my $j(@{$hash{$i}}) { my ($valname) = keys %{ $j }; print "valname = $valname\n"; print "content = ", $j->{$valname}[0], "\n"; # etc. } }