use Data::Dumper; my $free_table = {}; my $mastertitle = "title"; my $elementid = "foo"; my @unique_terms = qw(These guides were given a plug a few months ago before the JISC conference in fact, where they were displayed and I forget to pick them up. However, I rectified that oversight on Friday at that aforementioned news working group in the JISC offices in central London.); foreach my $index_term (@unique_terms) { # we have a three-level checking process to deal with # The word itself $free_table->{$index_term} = {} unless exists $free_table->{$index_term}; print "term = $index_term\n"; # The specific institution subdivision $free_table->{$index_term}->{$mastertitle} = {} unless exists $free_table->{$index_term}->{$mastertitle}; print "mastertitle = $mastertitle\n"; # "Archdesc" isad or "fond" isad # make a reference to the anonymous hash at this bottom level $data_type = int (rand 2) + 1; # Add the element to the bottom level $free_table->{$index_term}->{$mastertitle}->{$data_type} = {} unless exists $free_table->{$index_term}->{$mastertitle}->{$data_type}; $free_table->{$index_term}->{$mastertitle}->{$data_type}->{$elementid} = 1; } print( Dumper ( %{$free_table} ) );