while (<$new_in_file>) { print "BEFORE CHOMP: $_\n"; chomp; next if $. == 1; # remove header line s/POS/SAMPLE/ if $. == 2; s/\s+/,/g if $. == 2; # replace whitespace with a comma on ID row next if $. >= 3 and $. <= 9; # remove unwanted lines print "BEFORE SUBSTITUTION: $_\n"; s/\s+(\d)\|(\d)\S+/,$1 $2/g; # clean up the SNPs & put into CSV format print "AFTER SUBSTITUTION: $_\n"; print $new_out_file "$_\n"; }