An alternative to the various regular expression approaches would be to use index and substr to work along the text. This method makes no attempt at coping with the potential fragilities of the data format so YMMV.

use strict; use warnings; use 5.010; my $text = q{xxxAAsgdhsdgABudhwuACedAGuwydADwieuhwiudAEudwdfuw}; my $tag = shift || q{AA}; my $limit = q{ZZ}; my @records = (); my $prevPosn = index $text, $tag, 0; die qq{ERROR: First record '$tag' not found in text\n} if $prevPosn == -1; warn qq{WARNING: First record '$tag' not at start of text\n} unless $prevPosn == 0; while ( ( my $posn = index $text, ++ $tag, $prevPosn + 2 ) != -1 ) { push @records, substr $text, $prevPosn, $posn - $prevPosn; $prevPosn = $posn; last if $tag eq q{ZZ}; } push @records, substr $text, $prevPosn; say qq{>$_<} for @records;

The output.

>AAsgdhsdg< >ABudhwu< >ACedAGuwyd< >ADwieuhwiud< >AEudwdfuw<

I hope this is of interest.

Cheers,

JohnGG


In reply to Re: Character Text Delimiters by johngg
in thread Character Text Delimiters by Ninthwave

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.