I sense you don't want to build a huge nasty list. Well, you can use split for that:
while (length $source) { # make only one split (creating 2 parts) (my($rec),$source) = split /;/, $source, 2; # ... }
Or you could use a regex. That has the benefit of not removing content from $source.
while (my ($rec) = $source =~ /\G([^;]*)(?:;|$)/g) { # ... }
Or, if you're a major fan of C, I offer you strtok() in Perl:
use constant RE_MAGIC => bless [], 'RE_MAGIC'; use constant C_STYLE => bless [], 'C_STYLE'; { my ($re,$str); sub strtok { my ($s,$pat,$opt) = @_; if (defined $s) { local $^W; # in case $pat/$opt isn't a ref $re = ref($pat) eq "RE_MAGIC" ? qr/(?!\s*$)\s*(\S*)/ : $opt && ref($opt) eq "C_STYLE" ? qr/(?!(?:$pat)*$)((?:(?!$pat).)*)(?:(?:$pat)+|$)/ : qr/(?!(?:$pat)*$)((?:(?!$pat).)*)(?:(?:$pat)|$)/; $str = $s; } else { croak "no pattern for strtok()" if not defined $re; } $str =~ /\G$re/g and return $1; undef $re; undef $str; } } my $rec = strtok($source, ';'); while (defined $rec) { # ... $rec = strtok(); }
There are two special flags to send to this function -- RE_MAGIC is sent in place of the pattern, and signifies Perl's special split(' ', ...) behavior; C_STYLE splits on multiple occurrences of tokens (so that "a--b" split on "-" will return a and b, and no empty string).

japhy -- Perl and Regex Hacker

In reply to Re: Split long string MANY times? by japhy
in thread Split long string MANY times? 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.