As soon as you get into nesting, you really need a parser. Fortunately, some properties of your data language allow us to construct one rather easily.

use strict; use warnings; sub process_para { my ($para) = @_; if (my ($id) = $para =~ /^(\w+)/) { if ($id ne 'blabla5') { $para =~ s/^TEXT TO BE REMOVED\n//mg; } } print($para); } { my ($depth, $buf); while (<DATA>) { $buf .= $_; ++$depth if /\(\s*$/; --$depth if /^\s*\)\s*$/; #printf("[%d] %s", $depth, $_); if (!$depth) { process_para($buf); $buf = ''; } } die("Bad nesting\n") if $depth; } __DATA__
blabla_data[28] OUTPUT ( REQUIRED ( lead_up 0.193118 br fclk clkdom(3) early_lea clkdom(3) late_trail_dn -0.084738 br fclk clkdom(3) late_tra ) cext %0.00151055 min_ceff_up %0.034 TEXT TO BE REMOVED ) blabla5 [145] OUTPUT ( REQUIRED ( early qclk clkdom(6) early_l qclk clkdom(7) late_trail_dn -0.125163 bf qclk clkdom(7) late_t(7) TEXT TO BE REMOVED ) )

Update: With the new data format, you'll need

sub process_para { my ($para) = @_; if (my ($id) = $para =~ /^ [ ]* (\S+)/x) { if ($id !~ /^.*clk\[\d\]\z/) { $para =~ s/^ [ ]* QUALIFIED [ ]* \n//xmg; } } print($para); }

In reply to Re: Substitute in a subparagraph by ikegami
in thread Substitute in a subparagraph by guyov1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.