use Sys::Hostname qw(hostname); # not strictly necessary; exports it by default use Socket; my($addr) = inet_ntoa( (gethostbyname(hostname()))[4] ); print "$addr\n";