sub get_family_member { my @args = @_; my $who = shift @args; # <-- this var is not used my $families = shift @args; foreach my $family (%families) { if ($families->{$family}->{kid} eq "bart") { # <-- are you sure you want to hard-code 'bart'? I think you need $who return $dfamilies->{$family}->{kid}; # <-- typo in hash name last; # <-- this will never be reached since it already returned } } # no matches found: die here }