Net::IP is, of course, a great way, because it is easy and powerful. But, if you are going to analyze tons of them, you can use inet_pton from the Socket package instead, since it is 10-20 times faster than the version of the Net::IP object, even with a previously created object. And 4 times faster than ip_expand_address version:
use Net::IP; use Time::HiRes qw(gettimeofday tv_interval); use Socket qw(inet_pton AF_INET6); use bignum; use strict;
Running this on an arbitrary machine for me:
Net::IP elapsed: 2.059268 Net::IP Result: 2001:0db8:0000:0000:0000:0000:0000:0001 ip_expand elapsed: 0.482405 ip_expand Result: 2001:0db8:0000:0000:0000:0000:0000:0001 inet_pton elapsed: 0.132578 inet_pton result: 2001:0db8:0000:0000:0000:0000:0000:0001
source share