open IN, '<', 'test.txt' or die "Can't open 'test.txt' $!"; open OUT, '>', 'test.out' or die "Can't open 'test.out' $!"; while ( ) { next unless /\S/; tr/ \t/ /s; print OUT; # Updated -- thanks Narveson } close IN; close OUT;