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 } #### for (split(/\n/, $records)) { # do whatever with data now in $_ }