I thought about using the mkdir() from perl, but my problem is that if a nested directory structure doesn't exist
i.e. /foo/bar/foobar/
then the code
mkdir("/foo/bar/foobar/");
is going to fail. Therefore I used a system call with the -p option so that any depth of directory will be created without failures.
As for the recursion bottoming out, just run the code. If it runs inifinitely then it doesn't bottom out. If it exits out, then it has a base case.
Check out File::Path - it has a function mkpath which solves that problem for you. Anything to avoid an unnecessary system call ;-) (Also note that this is part of the standard perl distribution so you can just use it anywhere without having to require extra modules.)