# ..\perl.exe
# perlmonks http://perlmonks.org/index.pl?node_id=951536
# Text::CSV witer
use strict;
use warnings;
use Text::CSV;
my $input_file = "951536_in.csv";
my $output_file = "951536_out.csv";
my @rows;
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
#read file
open my $fh, "<:encoding(utf8)", $input_file or die "$input_file: $!";
while ( my $row = $csv->getline( $fh )) {
$row->[0] =~ s/^(.*)(\d+)$/abc$2/; # replace leading chars
$row->[1] =~ s/^(.*)(\d+)$/$1asd$2/; # insert between char and digit
$row->[2] =~ s/^(.*)(\d+)$/$1xyz/; # replace digits
push @rows, $row;
}
$csv->eof or $csv->error_diag();
close $fh;
#write file
$csv->eol ("\n");
open my $fh_out, ">:encoding(utf8)", $output_file or die "$output_file: $!";
$csv->print ($fh_out, $_) for @rows;
close $fh_out or die "$output_file: $!";
print "finish!\n";
####
a1,a2,a3
b1,b2,b3
c1,c2,c3
####
abc1,aasd2,axyz
abc1,basd2,bxyz
abc1,casd2,cxyz