perl -pe 's/A\s*\{.+?\}//s' <<'EOX' A { B 123 C xyz } EOX # prints exactly what the input is