Here is a way to do it with
Path::Tiny.
#!/usr/bin/env perl
use strict;
use warnings;
use Path::Tiny;
my $x='x';
my $y='y';
my $dirpath = path($x, $y);
$dirpath->mkpath;
my $outpath = path( $dirpath, 'z.txt' );
my $fh = $outpath->openw_utf8;
print $fh "\n It's ok.\n";
$fh->close;
print "\n Program is over.\n";
exit;
Server Error (Error ID 3470494a2048917)An error has occurred. The site administrators
have been notified of the problem and will likely
soon fix it. We thank you, for you're patients.