use NetAddr::IP; my $home_net = new NetAddr::IP '10.0.0/24'; # ... while () { my ($string_ip, $rest) = split(/\s+/, $_, 2); my $ip = new NetAddr::IP $string_ip; next if $home_net->contains($ip); # Happily process $string_ip and $rest as it is not from your home net # ... }