in reply to Perl syntax
our variables have package visibility but respect scope. In this case, $d has file scope.
Improve your skills with Modern Perl: the free book.