my $regex = qr/(123\.145\.14[6-9]\.2)|(135\.168\.[1-9][0-9][0-5]?\.[0-9][0-2]?[0-5]?)/o; print "$ip matched\n" if $ip =~ /$regex/;