tobyink has provided an excellent solution. For your future reference--and in case the need arises again--there are Perl modules that can be used for parsing the kind of text you have. Here's an example that uses Mojo::DOM to parse your <a> tags:

use strict; use warnings; use Mojo::DOM; my $text = <<END; <a> word1 word2 word3 </a> <a> word4 word5 </a> <a> word6 word7 </a> END my $dom = Mojo::DOM->new($text); my $i = 1; for my $chunk ( $dom->find('a')->each ) { print 'Chunk ' . $i++ . ': ' . $chunk->text . "\n"; }

Output:

Chunk 1: word1 word2 word3 Chunk 2: word4 word5 Chunk 3: word6 word7

Thus, each group that you need to analyze is contained by $chunk->text within the for loop.

Hope this helps!


In reply to Re: Repeating the same command in different portions of input by Kenosis
in thread Repeating the same command in different portions of input by albascura

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.