use IO::Socket::INET; open(F, "<", "nosuchfile"); # set $! my $socket = new IO::Socket::INET(); print "$!"; # prints "No such file or directory"