for (split /\n/, $longstring) { ... } #### open my $fh, '<', \$longstring; while (<$fh>) { .... }