foreach $key_1 (keys %hash_1) { foreach $key_2 (keys %hash_2) { $my_hash{$key_1}{$key_2} = something; } } ........ $vars = { my_hash= > \%my_hash }