use NetAddr::IP; my $hosts = 0; push @space, new NetAddr::IP->new($_) for <DATA>; $hosts += $_->num for @space; print "You have $hosts\n"; __DATA__ 10.0.0.0/16 172.16.0.0/24