use strict; use warnings; open my $fh_in , '<', 'test1.txt' or die "Can not open file test1.txt: $!"; open my $fh_out, '>', 'test2.txt' or die "Can not open file test2.txt: $!"; while (<$fh_in>) { s/\s+/\t/g; print $fh_out "$_\n"; } close $fh_out; close $fh_in;