if ($dbm1{"$accountAD"} # you have an accountAD to test && $dbm1{"$accountID"} =~ /^$accountAD$/) # ID is key AD is value