#!/usr/bin/perl use strict; use warnings; use Regexp::Common qw /net/; use IO::Prompt; my $ip; # formatting the input while ( $ip = prompt "Enter a valid IP address: ", -until => qr/^$RE{net}{IPv4}{-sep=> '.'}$/ ) { print "Your say: '$_'\n"; } # dotted-quad format to hexadecimal my $hex_ip = unpack "H*", pack "C4", split '\.', $ip;