my $ip_hex = 'fd010000000000000000000000000003'; my $ip_ascii = unpack("A16", pack("H32", $ip_hex)); my $sth = $dbh->prepare("INSERT INTO `accounting` (`IPv6_string`, `IPv6_binary`) VALUES (?, ?);"); my @values = ('fd01:0000:0000:0000:0000:0000:0000:0003', $ip_ascii); $sth->execute(@values);