foreach $line (split(/\r\n|\n/, $contents)) { print "$line\n"; }This handles lines that end in CR-LF (line HTTP and Windows) or LF (like Linux and iOS); the vast majority of situations. It also preserves blank lines. If you want to read a file into lines don't to the above, to do this:
open(FILE, 'myfile.txt'); while ($line = <FILE>) { chop($line); print "$line\n"; } close(FILE);