In your version, wouldn't inc %c be dec %c? Since you want the while loop to process $numtok times and if you keep inc %c, it would go on for ever?

So I should use $hfind instead of $hget, so the table is accessed more efficiently, right?

Wouldn't it be better to only do the hadd if with the %remtok, if no item match is found in the dns table? The way you have it, hadd is always processed, even if an item match is found in the dns table, right?

Also, thanks for reminding me about removing the item if there are no data values left for it.