use NetAddr::IP; my $ip = new NetAddr::IP 'loopback'; if ($ip->within(new NetAddr::IP "127.0.0.0", "255.0.0.0")) { print "Is a loopback address\n"; }