# Snippet 3 - your answer? use strict; use warnings; use Data::Dumper; my @primary = qw(foo-Alice bar-Bob); my @secondary = qw(p0-home p1-work p2-mobile); my @tertiary = qw(itemA-555abcd itemB-555zxyw); my %phonebook = (); for my $primary_element (@primary) { for my $secondary_element (@secondary) { # Similar to method 1 from snippet 2a: # a reference directly to @tertiary $phonebook{$primary_element}->{$secondary_element} = \@tertiary; # -- or -- # Similar to method 2 from snippet 2a: # a new anonymous array reference, containing the elements from @tertiary $phonebook{$primary_element}->{$secondary_element} = [ @tertiary ]; } } print Dumper \%phonebook;