while (<$csv_file>) { s/\Q$sep\E/\t/g; print $tab_file, $_; # ^- That comma should not be there }