for (my $i = 0; $i < scalar(@array); $i++) { my $subhash = $hash{$array[$i]}; # does not autovivify new $hash element next unless $subhash; # equivalent to "exists($hash{$array[$i]})" for (my $j = $i; $j < scalar(@array); $j++) { my $subarray = $$subhash{$array[$j]}; # same comments as above next unless $subarray; foreach my $value ( @$subarray ) { # do great deeds } } }