in reply to Copy Lines After Match **UPDATE**

use strict; use warnings; open (NEW, ">", "output.txt" ) or die "could not open:$!"; my $find = 'COMPUTER1'; my $inside = 0; my $data = ''; while (<DATA>) { next if (/^$/); $inside = 1 if /COMPUTER1/; if ($inside){ $inside=0; next; } else{ $data .= $_; print NEW $_ } } print '[' . $data . ']'; close(NEW) __DATA__ COMPUTER1 ACCT1 ACCT2 ACCT3 COMPUTER1 ACCT4 ACCT7 ACCT8 ACCT9

All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: Copy Lines After Match
by 2teez (Vicar) on Dec 18, 2015 at 07:09 UTC
    Hi vinoth.ree

    Am sure you know one can achieve the OP intended output without so much elaborate solution. like so:
    use warnings; use strict; while (<DATA>){ print unless /computer.|^\s+$/i; } __DATA__ COMPUTER1 ACCT1 ACCT2 ACCT3
    One can even take out the while loop and use grep like so:
    print grep{!/computer.|^\s+$/i}<DATA>;
    These gives the output:
    ACCT1 ACCT2 ACCT3 ACCT4 ACCT7 ACCT8 ACCT9
    @jalopez453,
    Please also note that the filehandle is written as __DATA__, double "_" not a single dash as did.
    Cheers!
    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      This assumes the data is really as simple as indicated, so that the question posed by the OP title is not really relevant. For the benefit of others who might find this thread by searching, the more detailed program is necessary.

      Dum Spiro Spero