It would probably be useful to print out $hostName before you use it. Your double backslash on the command line ("foo.pl \\hostname") may be converted to a single backslash when Perl gets it, but I'm guessing that it's getting converted in the backticks. You can escape them before it gets there like so:
$hostName =~ s/\\/\\\\/g;
Update: Thanks to ikegami for pointing out that my speculation was off the mark. DOS does not mangle backslashes on the command line. I thought it might, so I suggested printing out the variable to be sure. I'd have checked this myself, but I don't have Perl on Windows to try.