http://www.perlmonks.org?node_id=1018234


in reply to Re^3: Replace newlines only if not inside braces
in thread Replace newlines only if not inside braces

$data =~ s<(?:{{.*?}}|[^\n])*\K\n>{<br>\n}gs;

I think (didn't test it) that the * is two greedy, better *?.

Cheers Rolf