You'd have to do some timing to see if this is going to adversely effect your performance, but I'd guess that 10 or so regexp calls would be less expensive than a single db query.
My first step if it turned out to need optimization would be to have ad_host store its regexp results in a ns_set. You'd want to time that as well.
If you really really want to have variables pre-declared for you the only way I know of is to have a registered proc that computes your variables and then sources the requested script.