print "Valid IP\n" if 4 == grep { /^\d+$/ and $_ < 256 } split /\./, $ip; #### my regex octet {(\d ** 1..3) } my regex ip {^ ** 4 % '.' $}