use strict; use warnings ; my @csv = ; foreach my $line ( @csv ) { my $clean_line = $line ; while( $line =~ /"(.*?)"/g ) { my $match = $1 ; my $match_cleaned = $match ; $match_cleaned =~ s/,/~/g; my $location = index( $line, $match ) ; my $clean_line = substr( $clean_line, $location, length( $match ), $match_cleaned ); } print "$clean_line"; } __DATA__ 123,abc1,test1,"1,3,5",new,"abc,dfg,hj" 124,abc2,test2,"1,3,5",new,"abc,dfg,hj" 125,abc3*,test3,"*|1,3,5",new,"abc,dfg,hj"