sub foo { ... ## get $ref back from bar() my($ref, %locations) = &bar($dbh); ... my $location_text = $locations{$ref->{'location'}}; } sub bar { ... my $ref; while ($ref = $sth->fetchrow_hashref()) { my $id = $ref->{'id'}; my $location = $ref->{'location'}; $locations{$id} = $location; } $sth->finish; ## return $ref back to caller return $ref, %locations; }