my %file_attachments = ( '103496-1' => { 'CLVD' => '5678', 'COMP' => '1234', 'FD' => '0010', 'File' => 'text.txt'}, ); print Dumper(%file_attachments); print "\n"; my %newfile_attachments; my $fn; my %newfile_attachments; foreach $fn (keys %file_attachments) { $newfile_attachments{$fn->{FirstNum}}= $fn; delete $fn->{FirstNum}; } print Dumper(%newfile_attachments); print "\n"; #### > perl hashofhash.pl "my" variable %newfile_attachments masks earlier declaration in same scope at hashofhash.pl line 17. $VAR1 = '103496-1'; $VAR2 = { 'FD' => '0010', 'COMP' => '1234', 'CLVD' => '5678', 'File' => 'text.txt' }; Can't use string ("103496-1") as a HASH ref while "strict refs" in use at hashofhash.pl line 19.