$str = join ',', map {sprintf "%02x", $_} unpack 'C*', $value; # And back $str =~ s/,//g; $value = pack "H*", $str;