Вы можете попробовать это:
#!/usr/bin/perl
use warnings;
use strict;
use NetAddr::IP;
my $first = NetAddr::IP->new('10.0.0.1/24');
my $second = NetAddr::IP->new('10.0.0.5/32');
if ($second->within($first)) {
printf "%s is within %s\n", $second, $first;
} else {
printf "%s is not within %s\n", $second, $first;
}