Here's an approach that avoids the scary  (?{ code }) and  (??{ code }) regex constructs, but whether it's more readable than your  while loop is another question.

>perl -wMstrict -le "my $s = '_+0GAA__+1GAA__+2GGAA__+3GGGAA_'; print qq{'$s'}; $s =~ s{ ( \+ (\d+) [ACGT]+ ) } { (my $r = $1) =~ s{ \+ \d+ [ACGT]{$2} }{}xms; $r }xmsge; print qq{'$s'}; " '_+0GAA__+1GAA__+2GGAA__+3GGGAA_' '_GAA__AA__AA__AA_'

Note that the  '+0ACGT' sequence is handled in a way that seems consistent with your original regex, but that I don't know to be correct.

Update: Here's a version using substr that might be a bit more readable.

>perl -wMstrict -le "my $s = '_+0GAA__+1GAA__+2GGAA__+3GGGAA_'; print qq{'$s'}; $s =~ s{ ( \+ (\d+) [ACGT]+ ) } { substr $1, 1 + length($2) + $2 }xmsge; print qq{'$s'}; " '_+0GAA__+1GAA__+2GGAA__+3GGGAA_' '_GAA__AA__AA__AA_'

In reply to Re: Regex fun by AnomalousMonk
in thread Regex fun by Hena

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.