my %referencedSentences = (); foreach my $j (@{$words[$i]}) { if (($j ne "$j") || ($j ne "v")) { if (exists $sentences->{$j}) { %referencedSentences{%j} = $sentences->{$j}; } } } push (@temp, \%referencedSentences);