sub valid_ip { my $bits = 0; foreach (split (/\./, $_[0])) { return unless /^\d+$/ && $_ >= 0 && $_ < 256; $bits++; } return $bits == 4; }