for $find qw((1958 1959 1960 1961 1962 1963 1964)){ $index = 0; # index is defined to go down the array of each year while (defined $bros->{$find}->[$index]->{$key}){ if ($bros->{$find}->[$index]->{$key} =~ /$data/i){ # since we found one, we push the brothers data structure and # year of graduation in to the results hash push (@res,{brother => $bros->{$find}->[$index], year => $find}); } # end if $index++; } # end while } # end find