use Storable qw(dclone); foreach my $b1 (keys %{$ref_1->{'1'}}) { if(exists $ref_1->{'2'}->{$b1}) { $ref_1->{'2'}->{$b1}->{'1'} = dclone $ref_1->{'1'}->{$b1}; } } print Dumper $ref_1;