Your data looks rather like it may be XML, in which case you may be better to look at some of the XML modules such as XML::Twig and XML::TreeBuilder. As an example of how these things can help consider:

#! /bin/perl -w use strict; use warnings; use XML::TreeBuilder; my $root = XML::TreeBuilder->new (); $root->parse (do {local $/; <DATA>;}); my $frame_marker = 'data'; my @dataNodes = $root->look_down ('_tag', 'data'); my $nodeCount; for my $nodeIndex (0 .. @dataNodes - 1) { my @strings = $dataNodes[$nodeIndex]->look_down ('_tag', 'string') +; print "Data node " . ($nodeIndex + 1) . "\n"; print " ", $_->as_text (), "\n" for @strings; } __DATA__ <root> <data> <string>1 some stuff</string> <string>1 some more stuff</string> <string>1 yet more stuff</string> <string>1 enough stuff</string> </data> <data> <string>2 some stuff</string> <string>2 some more stuff</string> <string>2 yet more stuff</string> <string>2 enough stuff</string> </data> <data> <string>3 some stuff</string> <string>3 some more stuff</string> <string>3 yet more stuff</string> <string>3 enough stuff</string> </data> </root>

Prints:

Data node 1 1 some stuff 1 some more stuff 1 yet more stuff 1 enough stuff Data node 2 2 some stuff 2 some more stuff 2 yet more stuff 2 enough stuff Data node 3 3 some stuff 3 some more stuff 3 yet more stuff 3 enough stuff

DWIM is Perl's answer to Gödel

In reply to Re: Premature End-of-File - Scope problems? by GrandFather
in thread Premature End-of-File - Scope problems? by bratwiz

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.