# in your code, $text would be each line of the file inside a loop my $text = 'asfd asdf, fdsa asd "fds"asf 123'; $text =~ s/"/\\"/g; $text = qq|"$text"|; $text =~ s/\t/","/g; print "$text\n";