while (<>) { my @lines; if ( /\n$/ ) { tr/\r\n//d; @lines = ( $_ ); } else { @lines = split /\r/; } for my $line ( @lines ) { # do stuff with each line of text } }