use Regexp::IPv6 qw($IPv6_re); use IPv4; my $address = ; # Add your address here. if ($address =~ /^$IPv6_re$/) { print "IPv6\n"; } elsif (IPv4::check_ip($address)) { print "IPv4\n"; } else { print "Neither.\n"; }