/(\d\.?){1,4}/ # $1 is last octet matched /((\d\.?){1,4})/ # $1 is IP address, $2 is last octet matched #### echo 1234.45.67.890 | perl -ne'printf "%X%X%X%X",split /\./'