Something in this way can work, I will just point that a SCALAR in Perl is not a char*, since it can have UTF8/UNICODE values. We should use vec() to ensure that the data will be exactly the same that is appended with pack(). Also vec() already does the pack trick for us: