I applaud your creativity, however for simplicity's sake the builtin 'mkpath' module can make the entire directory at once, using the directory name extracted by the builtin 'dirname' module. I have found that when I have to go back and maintain what I've written, the simpler I can make it, the better it is for me or some other developer.
1 use File::Path;
2 use File::Basename;
3 my $file = '/foo/bar/baz/baz/bax/cat/dog';