use Regexp::Common qw /balanced/; my $re = qr{$RE{balanced}{-begin => "{{"}{-end => "}}"}}; $text =~ s/$re//g;