#!/usr/bin/env perl use Modern::Perl 2011; use autodie; # I create a multidimensional hash my %one = ('a' => [1, 2], 'b' => [3, 4], 'c' => [5, 6]); # I create a copy: # wrong way: #my %two = %one; # right way: my %two; for(keys %one) {$two{$_}[0] = $one{$_}[0]; $two{$_}[1] = $one{$_}[1]} # I print them: say "Before:\n\%one:"; for(sort keys %one){say "$_\t$one{$_}[0]\t$one{$_}[1]"} say '%two:'; for(sort keys %two){say "$_\t$two{$_}[0]\t$two{$_}[1]"} # Then I modify the copy: for(sort keys %two){$two{$_}[1] = 'two'} # And I print again: say "After:\n\%one:"; for(sort keys %one){say "$_\t$one{$_}[0]\t$one{$_}[1]\tOk!!!"} say '%two:'; for(sort keys %two){say "$_\t$two{$_}[0]\t$two{$_}[1]"} # I receive this output: #Before: #%one: #a 1 2 #b 3 4 #c 5 6 #%two: #a 1 2 #b 3 4 #c 5 6 #After: #%one: #a 1 2 Ok!!! #b 3 4 Ok!!! #c 5 6 Ok!!! #%two: #a 1 two #b 3 two #c 5 two