use warnings; use strict; use File::Edit::Portable; my $rw = File::Edit::Portable->new; my $fh = $rw->read('input.txt'); my $wfh = $rw->tempfile; while (<$fh>){ chomp; my @line = split('\s+', $_); print $wfh "$line[2]\t$line[7]\n" if $line[7] > 0; } $rw->write(copy => 'input.txt.new', contents => $wfh);