Unless you want special handling for the large invoices, it looks like your code is already doing that. Consider the following mutation of your code for demonstration purposes:

use warnings; use strict; my $chunksize = 50; my $filenumber = 0; my $outsize = $chunksize + 1; my $eof = 0; while (<DATA>) { if ($outsize > $chunksize and /^11/) { $outsize = 0; $filenumber++; print "*** New file number $filenumber\n"; } print "$_"; $outsize += length; } __DATA__ 11 The first invoice. We get this whole thing even though it exceeds the 50 character limit because the conditional code requires an invoice marker before it will start a new file. 11 Second 11 Third 11 Fourth invoice 11 Fifth invoice This one is longer, but not excessive 11 Sixth: break before because limit hit in fifth 11 seventh and final

Prints:

*** New file number 1 11 The first invoice. We get this whole thing even though it exceeds the 50 character limit because the conditional code requires an invoice marker before it will start a new file. *** New file number 2 11 Second 11 Third 11 Fourth invoice 11 Fifth invoice This one is longer, but not excessive *** New file number 3 11 Sixth: break before because limit hit in fifth 11 seventh and final

How would the output be different to achieve what you want?


DWIM is Perl's answer to Gödel

In reply to Re: Removing Large Invoices from a Data File by GrandFather
in thread Removing Large Invoices from a Data File by JayDog

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.