http://www.perlmonks.org?node_id=422470


in reply to Including special characters in a search and replace

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.