in fact those need to be references due to list flattening.
your %hash1 is not built as you want (same for %hash2).
you can see this by just printing out your data structures and try to guess what happens:
use strict;
use Data::Dumper;
my %hash1;
# fill %hash1 here
print Dumper \%hash1;