$dir = "/home/Bob/XXX"; $dir =~ m/(\/.*)\/([^\/]+)\/?$/ and ($base,$dirname) = ($1,$2); mkdir $dir unless scalar grep(m/$dirname/i, glob("$base/*"));