in reply to using a variable as a filehandle

Here's two ways of doing it:
while () { $_ = substr($records, $p, index($records, "\n", $p) - $p); last if (!$_); $p += length($_) + 1; # do whatever with data now in $_ } while ($records =~ /(.*?)\n/g) { # do whatever with data now in $1 }
I benchmarked both for 10,000 iterations on a 1,000 record string. The substr took 22 seconds vs 46 seconds for the regex. Both assume there's a \n on the end of the string.

Using split directly cuts it to 10 seconds, but requires about twice the memory:

for (split(/\n/, $records)) { # do whatever with data now in $_ }