use strict; use warnings; #using three argument for open(); open ( my $output, '>', 'output' ) or die "cannot open file for writing -$!"; #read and print all on one line ;) print ( $output $_ ) while(); __DATA__ 1st line 2nd line 3rd line 4th line End of file