I could be wrong, but what I think you need to do is break out of the loops with a last statement. What I'd try would be to name the code blocks (i.e. FIRST and SECOND) then after your split, do last FIRST;. I think that will break you out of the loops. This is untested and may not work quite the way I described it.
in reply to Problem changing only first occurence of pattern in file