use strict; use warnings; my $outdir = "output"; if (! -d $outdir) { warn "Creating '$outdir'"; mkdir $outdir or die "Couldn't create '$outdir': $!"; }; my $outname = "$outdir/test.txt"; open my $outfile, ">", $outname or die "Couldn't create '$outname' : $!"; print $outfile, "Hello World\n";