http://www.perlmonks.org?node_id=194177


in reply to How to scan a file, find a character string and print from that string to EOF

Without changing your code too much, you might do something like this. The basic idea is that you have a flag telling you whether you've hit DETS01 yet or not, then flip the flag when you hit it.

#!/usr/bin/perl -w open (INPUT, "target.txt") or die "can't read from target:$!\n"; open (OUTPUT1, ">file1.txt") or die "can't write to file1.txt:$!\n"; open (OUTPUT2, ">file2.txt") or die "can't write to file2.txt:$!\n"; # # my $firsthalf = 1; while (<INPUT>) { if ($_ =~ /^DETS01/) { $firsthalf = 0; } if ($firsthalf) { print OUTPUT1 $_; } else { print OUTPUT2 $_; } } close (INPUT); close (OUTPUT1); close (OUTPUT2);

Edit: Removed commas after filehandles in prints. Thanks, tadman!

"One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison