my $outfile = "result.txt"; open my $OUT, ">", $outfile or die "could not open $outfile $!"; # idiomatic way to open a file for writing