I personally believe that since the text you're operating on seems highly structured, and more precisely a proper language, then a fully reliable solution would comprise to write a parser. Perhaps one exists already. However, if you're fairly sure that the your data is regular enough then you may want to slurp it all at once and process it with somewhat naive regexen. The following program follows such an approach does work as expected on your sample, but be warned that it may fail on the full data.

#!/usr/bin/perl use strict; use warnings; use 5.010; sub doit { my ($head, $body) = @_; $body =~ s/QUALIFIED// unless $head ~~ /^\w+?clk\[\d\]/; $head . $body; } local $_ = do { local $/; scalar <DATA> }; s/ ^ \b ( [ \w \s \[ \] ]+ \s+ \( ) $ ( .*? ^\)$ ) /doit $1, $2/gemsx; print; __END__ qclk[6] INPUT ( ! "asdk fd sasd" VALID ( late_lead 3 ar qclk slope 20 late_lead 3 af qclk slope 04 early_dn 8 ar qclk slope 6 early_up 6 af qclk slope 6 ) cext %0.00394757 cmax %0.005504 QUALIFIED ) clkout_qclk_61[3] OUTPUT ( ) clkout_qclk_61[2] OUTPUT ( REQUIRED ( earlyp 0.5 br qclk clm(2) latel_up 5 bf qclk clk(2) ) REQUIRED ( early_lead_dn 0.004 bf qclk clkdom(2) late_trail_dn 0.005 br qclk clkdom(2) ) cext %0.0647336 max_ceff_up %0.187 QUALIFIED )
--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re^6: Substitute in a subparagraph by blazar
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.