There is a reason why Perl does not let you nest if's directly. It is confusing. Perl allows enough cryptic things, but even Larry drew the line at that one.
Create a block for that. They're cheap.
\nunless (-d $foo) {\n mkdir($foo) or die "Cannot mkdir '$foo': $!";\n}\n
Cheers,
Ben