in reply to Unable to remove the ^M character

You do not say which operating system you are running the Perl on. This is important because Windows has the notion of text files, whereas UNIX does not.

When Perl on Windows reads a text file it removes the "\r" for you, so if you are running the code on Windows, it probably doesn't have a "\r" in the record to remove! Perl then adds the "\r" (^M) on Windows when you write the file as text with a "\n" line ending.

If you wish to write a UNIX style file on Windows then set binmode on the file handle before writing the file.

Replies are listed 'Best First'.
Re^2: Unable to remove the ^M character
by kkavitha (Initiate) on Jul 24, 2009 at 10:11 UTC

    Thanks for your information. It is working fine.

Re^2: Unable to remove the ^M character
by kkavitha (Initiate) on Jul 24, 2009 at 11:40 UTC

    Tried with binmode. However it is working fine for the file which not resides with ^M. but ^M is lost for the file which resides with ^M

      <hi>,
      you can use this UNIX command dos2unix
      , -Raja