You may want to make sure that $newdir actually contains the directory's name, you can simply print it. Another thing is that while you're trying to create the directory with permissions 766 the next line you change to 777. You could simply
do { mkdir $newdir, 0777 || die "Yikes!, $!\n" } unless (-e $newdir)