in reply to escape each backslash of each array element

I see a problem with: @row=('aa','bb','\\c\c\','d\d');

I believe the compiler is reading an odd number of tick marks (') because your example is escaping the tick mark that follows the last c\ combination.

When I read @row as input (see below), I get the same output you showed for "result". I assumed that was your desired output.

my @row=(<DATA>); my $separator=','; foreach (@row) { s/(\\+)/$1$1/g; } print join($separator, @row); print "\n"; __DATA__ aa,bb,\\c\c\,d\d
Output: aa,bb,\\\\c\\c\\,d\\d