It's not really clear what you are trying to do, but here are my assumptions:

I assume that the above line is an actual line from the file, and depending on how you have read it in, it most probably is getting read line by line, therefore, $line will not contain the concatenated lines together and that's why your regex is not working (besides escaping the \ of \r and \n)... so here's a quick snippet illustrating how to do it (using same regex from Re: Including special characters in a search and replace):

open IN, "<", "thefile.ext" or die "Cannot open file: $!\n"; my $i = 0; while (my $line = <IN>) { $line =~ s/,39,/,3$fields[$i++],/g; # now what you want to do with $line is up to you } close IN;

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/
Are you a Linux user in Lebanon? join the Lebanese Linux User Group.

In reply to Re: Including special characters in a search and replace by Chady
in thread Including special characters in a search and replace by wudaben

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.