If I've understood what you want to achieve (showing the output you expect would help), the following may do the trick:

use strict; use warnings; my %tags; my $printing; while (defined (my $line = <DATA>) || defined $tags{IT}) { if (defined $line) { my ($tag) = $line =~ /^{(\w+)}/; if (! $tag) { print $line if $printing; next; } $printing = $tag =~ /^(TAG|ID)$/; if ($tag ne 'IT') { ++$tags{$tag}; next; } } print $tags{IT} if (! $tags{LINE} || ! $tags{ID}) && defined $tags{IT}; %tags = (IT => $line); } __DATA__ {IT} 343 1 {DATE} 090104 {LINE} LEGISLATORS VISIT SENIOR APARTMENT COMPLEX {TAG} 1lutherridge0104.ART {ID} 234 {IT} 434 2 {DATE} 090104 {LINE} LEGISLATORS VISIT SENIOR APARTMENT COMPLEX

Prints:

1lutherridge0104.ART 234 {IT} 434

The key is to 'remember' what has been seen and perform the extra processing when the next section is detected. Note the tricky stuff that gets the last section handled correctly when the end of file is reached.


True laziness is hard work

In reply to Re: print line by GrandFather
in thread print line by Anonymous Monk

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.