title: How to replace ^M with a new line in perl
body: <p>My test file has "n" number of lines and between each line there is a ^M, which in turn makes it one big string.  The code I am working with opens said file and should parse out a header and then the subsequent rows, then searches for the Directory Path and File name. But because the file just ends up as a big string it doesn't work correctly</p>
  
  <pre><code>#!/usr/bin/perl
  #use strict;
  #use warnings;
  
  open  (DATA, "&lt;file.txt") or die ("Unable to open file");
  
  my $search_string = "Directory Path";
  my $column_search = "Filename";
  my $header =  &lt;DATA&gt;;
  my @header_titles = split /\t/, $header;
  my $extract_col = 0;
  my $col_search = 0;
  
  for my $header_line (@header_titles) {
    last if $header_line =~ m/$search_string/;
    $extract_col++;
  }
  for my $header_line (@header_titles) {
    last if $header_line =~m/$column_search/;
    $col_search++;
  }
  
  print "Extracting column $extract_col $search_string\n";
  
  while ( my $row = &lt;DATA&gt; ) {
    last unless $row =~ /\S/;
    chomp $row;
    my @cells = split /\t/, $row;
   $cells[74]=~s/:/\//g;
  $cells[$extract_col]= $cells[74] . $cells[$col_search];
  print "$cells[$extract_col] \n";
  
  }
  </code></pre>
  
  <p>When i open the test file in VI i have used</p>
  
  <pre><code>:%s/^M/\r/g
  </code></pre>
  
  <p>and that removes the ^M's but how do i do it inside this perl program? When i tried a test program and inserted that <code>s\^M/\r/g</code>  and had it write to a different file it came up as a lot of Chinese characters. </p>