in reply to execute loop code for every occurence of regex

your .* in the middle is greedy. fix it with a .*? or something a little more specific is possible
perl -e '$l="|i ba |l L1 |i b2 |l L2"; while ($l=~ /\|i([^|]*).*\|l([^ +|]*)/g) {print "$1 $2\n"}' ba L2 perl -e '$l="|i ba |l L1 |i b2 |l L2"; while ($l=~ /\|i([^|]*).*?\|l([ +^|]*)/g) {print "$1 $2\n"}' ba L1 b2 L2

Cheers,
R.