my %hashSeg; for my $ip (sort keys %hashIPs) { if ($ip =~ /(\d{1,3}\.\d{1,3}\.\d{1,3})\.\d{1,3}/){ my $seg = $1; $hashSeg{$seg}++; } } for my $seg (keys %hashSeg){ if ($hashSeg{$seg} ne '255'){ print "$seg is not a full \/24\n"; } else { print "$seg is a full \/24\n"; } }