You see "Invalid argument" because the constructor is trying to resolve the host name, receives an error message, and returns EINVAL in $! . If you use the IP address in $host , you will see a real error: "Network is unavailable."
In addition, IO::Socket::INET sets up $@ to qualify the error returned in $! , so if you print $@ as well as $! , you will see "Bad hostname" google.com '', which is probably an even better diagnosis than the "Network is unavailable", which you will receive with an IP address instead of a host name. In both cases, it should be immediately clear what is happening.
Grrrr source share