open my $handle, '<', $path_to_file or die "Not able to open file: $!"; chomp(my @lines = <$handle>); close $handle or warn "Not able to close file: $!"; #### open my $fh, '>', "output.txt" or die "Cannot open output.txt: $!"; foreach (@lines) { print $fh "$_\n"; } close $fh or warn "Not able to close output.txt: $!"; #### print $fh join ("\n", @lines);