use strict; use warnings; my %people; my @sentences = ("here i am","i am me"); # Create $people{me} - it contains a HASH-REFERENCE $people{me} = {ROW=>0, DOB=>1985, SPEAK=>[@sentences], # This element is an array-reference, created from a copy of the array @sentences }; @sentences = ("there she is"); $people{friend} = {ROW=> 1, DOB=> "1984", SPEAK=>[@sentences] # }; foreach my $person (sort keys %people) # Use the KEYS function to get hash keys, then sort them { addDOBToDatabase( $people{$person}->{ROW}, $person, $people{$person}->{DOB}); my $sentenceRow = 0; foreach my $sentence ( @{ $people{$person}->{SPEAK} }) # Walk through each element of the array-reference { $sentenceRow++; addSentenceToDatabase( $sentenceRow, $people{$person}->{ROW}, $sentence); } }