Variation on myocom's technique. Could be a little more elegant with IO::File:
use strict; use warnings; my ($input_file) = @ARGV; # Auto-generate output names based on input name my @output_file = map { "$input_file.$_" } 1..2; # Open up all the required filehandles open($input_fh, "<", $input_file) || die "Could not open $input_file\n"; my @out_fh; open ($out_fh[0], ">", $output_file[0]) || die "Could not write to $output_file[0]\n"; open ($out_fh[1], ">", $output_file[1]) || die "Could not write to $output_file[1]\n"; # Start by writing to the first filehandle my $fh = $out_fh[0]; while (<$input_fh>) { $fh = $out_fh[1] if (/^DETS01/); print $fh; } # Now close out everything foreach my $out_fh (@out_fh) { close($out_fh); } close($input_fh);
This rotates filehandles if the string "DETS01" occurs. The first bit is in the first file, the second in the second. So the file "input.txt" makes "input.txt.1" and "input.txt.2".

In reply to Re: How to scan a file, find a character string and print from that string to EOF by tadman
in thread How to scan a file, find a character string and print from that string to EOF by 0p3nfac3

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.