$SQLBuy = $dbh_metro->prepare("SELECT * FROM BuyersSellers WHERE FileNumber ='".$filenumber."'"); $rv = $SQLBuy->execute; while (my $hash_ref = $SQLBuy->fetchrow_hashref) { push @BuySellHashref, \$hash_ref; } $SQLBuy->finish; undef $SQLBuy; foreach (@BuySellHashref) { $SQLPEOPLE = $dbh_metro->prepare("SELECT * FROM People WHERE PersonID = '".${$_}->{PersonID}."'"); $rv = $SQLPEOPLE->execute; while (my $hash_ref = $SQLPEOPLE->fetchrow_hashref) { ${$_}->{PersonID} = \$hash_ref; } $SQLPEOPLE->finish; undef $SQLPEOPLE; } #### foreach $buysell (@BuySellHashref) { if (${$buysell}->{BuyerORSeller} =~ /BUYER/i) { print qq|$buysell->{PersonID}->{LastName}|; } } #### $VAR1 = \{ 'FileNumber' => '01-0001', 'PersonID' => \{ 'FirstName' => 'JOE', 'PersonID' => '01SMITH', 'MiddleInitial' => 'D', 'LastName' => 'SMITH' }, 'BuyerSellerID' => '01-0001Bjoesmith', 'BuyerORSeller' => 'BUYER' };