in reply to execute loop code for every occurence of regex

What do you mean with the first occurence?

If your input is: |i abc |l def |i ghi |l jkl, then the output will be: abc|jkl, which doesn't seem as the first pair to me...

The problem with your code is that * (and +) are greedy.
You can find more information about that, and how to fix it, in the perlre pod and/or perlretut pod. You can/should look for greedy and/or maximal match.

  • Comment on Re: execute loop code for every occurence of regex