use Socket; my $address = '127.1'; my $hex_addr = sprintf "%02x.%02x.%02x.%02x", unpack 'C*', inet_aton($address);