use strict; use warnings; use File::Path; use File::Copy; use File::Spec; # Assemble a new dir name and create it my $dirpath = File::Spec->catdir( 'C:', 'dir1', 'dir2' ); mkpath( $dirpath ); # make sure the dir we tried to create exists, using -d (one option) my $install_error = 0; unless( -d $dirpath ) { $install_error = 1; } # (stuff if mkpath failed) my $pathfile = File::Spec->catfile( $dirpath, 'myfile.txt' ); my $copy_status = copy( 'myfile.txt', $pathfile ); if( $copy_status == 1 ) { print " copied myfile.txt to $dirpath\n"; } else { print " *** Error copying file: $!\n"; }