use IO::Socket::INET; my $sock = IO::Socket::INET->new( PeerAddr=> "example.com", PeerPort=> 80, Proto => "tcp"); my $localip = $sock->sockhost;