foreach ($string) { while (1) { s/\[(\w+)\]/&mlookup($1)/e and next; s/\[(\w+)\[(\d+);(\d+)\]\]/&tlookup($1,$2,$3)/e and next; s/\[(\w+)\((\w+(,\w+)*)\)\]/&flookup($1,$2)/e and next; last; } }