Really, the simplest way to do what you're asking is to change your script to make use of features/identifiers already in mIRC that are similar (but not the same) to what you're suggesting. Instead of using dynamic variables, use a hash table.
You could simply make two hash tables,
var and
iable, using a number for each item just like you are with the variables, and then use a simple loop like this:
var %i = 1
while $hget(var, %i) != $null {
if $hfind(iable, $v1).data {
[color:red]; A match has been found. Do something here[/color]
}
inc %i
}
This way the need for ugly embedded while loops is removed. $hfind() is fast, and a single while loop using it will be able to handle probably hundreds of items before it becomes noticeably slow.
Personally I think with hash tables and $hfind(), an identifier for variables like you're asking isn't really necessary. But then again what do I know, maybe a lot of people have been waiting for this.