@filetoread = ; # read in file all at once my $linestooutput = ''; # place to save output until the end foreach (@filetoread){ @Line = split /\s+/; #split defaults to $_ $linestooutput .= join("\t",@Line[@ColumnNumbers])."\n"; } print OUTFILE $linestooutput; # write output # or even shorter @filetoread = ; $linestooutput .= join("\t",(split /\s+/)[@ColumnNumbers])."\n" foreach (@filetoread); print OUTFILE $linestooutput;