open FILE1, "contest.txt" or die "Could not open contest.txt: $!"; open FILE2, ">contest2.txt" or die "Could not open contest2.txt: $!"; while (<FILE1> ) { print FILE2; last if $. == 4; } close FILE1; close FILE2;