There's no need to put $dir in quotes if it's the ONLY thing in quotes. And putting an octal number in quotes is A Bad Thing. And you don't need to chmod() a directory after you mkdir() it. And you should check the return calls of mkdir(), chmod(), etc.

Perl converts octal and hexadecimal numbers to decimal when it sees them as numbers (not strings).

As for mkdir() not making your directories 0777, that is because your umask() setting is 0022. To get around that, you CAN use chmod() after you've made the directory, or can use Perl's umask() function: