The regex answers already given are the best, most "Perlish" solutions.
Here are three other ways to remove or replace a single character, using index and substr.

my $data1 = "abc\ndef"; my $data2 = "foobar\nbaz"; my $data3 = "Albus\nPercival\nWulfric\nBrian\nDumbledore\n"; my $pos1 = index($data1, "\n"); # $pos1 is 3 my $pos2 = index($data2, "\n"); # $pos2 is 6 my $pos3 = index($data3, "\n"); # $pos3 is 5 # Put together the part before $pos1, # and the part after $pos1. $data1 = substr($data1, 0, $pos1) . substr($data1, $pos1+1 ); # Tell the part of the string that contains # the "\n" to resize itself to nothing, as an lvalue. substr($data2, $pos2, 1) = ''; # Replace the part of the string that contains # the "\n" with three spaces. substr($data3, $pos3, 1, ' '); use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper($data1, $data2, $data3); # prints: # $VAR1 = "abcdef"; # $VAR2 = "foobarbaz"; # $VAR3 = "Albus Percival\nWulfric\nBrian\nDumbledore\n";

In reply to Re: Remove Carriage Return by Util
in thread Remove Carriage Return by icg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.