I know how to use m//g for search and s/// for substituting but I don't know how to to a "double search": after finding my match - finding another match inside.

I personally believe that -letting your actual problem aside for a moment- as soon as you know how to write a sub, you should have solved your problem: you should know that the /e modifier allows you to include code in the substitution part of an s///. So just capture the text you want to process, and process it in a separate sub. Of course, you can also inline the sub code in the substitution part itself. But then you will have to pay much care to the delimiters, or else the perl parser may easily get confused. For example, the whole program I suggested elsewhere may be cast into the form of a single substitution:

s/ ^ \b ( [ \w \s \[ \] ]+ \s+ \( ) $ ( .*? ^\)$ ) / my ($head, $body)=($1, $2); $body =~ s|QUALIFIED|| unless $head ~~ m|^\w+?clk\[\d\]|; $head . $body /gemsx;
--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re: 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.