#non shared hash version my %abc; my @parents = qw( a b c ); my @children = qw( 1 2 3 4 ); for my $parent ( @parents ) { for my $child ( @children ) { $abc{ $parent }{ $child } = 1; } } #### # shared hash version. my %abc : shared ; my @parents = qw( a b c ); my @children = qw( 1 2 3 4 ); for my $parent ( @parents ) { unless (exists $abc{$parent}) { my %p : shared; $abc{ $parent } = \%p; } for my $child ( @children ) { unless ( exists $abc{$parent}{$child} ) { my %c : shared; $abc{$parent}{$child}=\%c; } $abc{ $parent }{ $child } = 1; } }