use warnings; use strict; # I am using the latest stable version of Perl for this exercise use 5.30.0; while (<>) { # Skip lines ending with an empty field next if substr($_,-2) eq "\t\n"; # Remove "\n" chomp; # Split matching lines into fields on "\t", creating @fields my @fields=split(/\t/,$_); # Copy only the desired fields from @fields to create a new # line in TSV format # This can be done in one simple step in Perl, using # array slices and the join() function my $new_line=join("\t",@fields[2,3,12..18,25..28,31]); # ... }