Good catch on the inc/dec error. In fact, with it starting at the maximum, then increasing, it would only run once, not forever.

I recommended using $hfind rather than $hget to save you from having to loop through the dns hash table each time. In this case, $hfind is more efficient than $hget since it incorporates the search rather than having to get the item then compare it.

The hadd (before altering the code) was always processed so that any remaining dns values that were in the match string, but not the dns table would be maintained.