in reply to sorting hashes

my $rHash = \%hash; for my $k1 = (sort keys %$rHash) #outer key, this works
Is this real code? # this should NOT "work"

I suppose you want

for my $k1 (sort keys %$rHash)
Oh, and BTW why this
my $rHash = \%hash;
additional level of referencing? (Given that you do it only to dereference it later)