$sth->bind_columns( undef, \$dest_service_id, \$dest_stop, $depart_dest); while ($sth->fetch()) { if (exists ($ids{$dest_service_id}) { print "ID $id exists in both origin and destination set\n"; print "\t$ids{$dest_service_id}{stop_reference} => $dest_stop\n"; print "\t$ids{$dest_service_id}{depart_time} => $depart_dest\n"; } }