And, of course, as soon as I sent my question in I solved the looping problem by using $' to search the portion of the string that remained after the first regex match... D'oh! James