use warnings;
use strict;
use 5.012;
my $data = <<'END_OF_TEXT';
foo
bar
{{
alpha
beta
}}
baz
END_OF_TEXT
$data =~ s/
(?: #Non-capturing group
{{.*?}} #Text enclosed by double braces
\K #Exclude what's to the left of \K from match
)? #Match whole group 0 or 1 time
\n
/\n
/gxms;
say $data;
--output:--
foo
bar
{{
alpha
beta
}}
baz