in reply to what does $subdir = "$BASEDIR/$subdir" unless $subdir =~ m{^/}; do

Another (more robust, platform-indpendent) way would be to use File::Spec:
use File::Spec; $subdir = File::Spec->rel2abs($subdir, $BASEBIR);
But anyways, your confusion may come from seeing m{^/} instead of /^\//, which are equivalent. See perlop and perldoc:perlre for the m// operator. It could also be written as m#^/# or m!^/! (or many others). But any way it's written, it is a regex that is checking for a leading slash -- i.e. if the path is absolute or not. IFF that fails (since "unless" reads as "if !") then it prepends a base directory to $subdir. So after that statement $subdir should be an absolute path if it wasn't already.