open my $fh, '<', $filename or die "Can't open file. $!\n"; while (<$fh>){ $_ =~ s/\cM\cJ|\cM|\cJ/\n/g; # do somthing with line }