perldoc -f pack
h A hex string (low nybble first). H A hex string (high nybble first). ... * The "h" and "H" fields pack a string that many nybbles (4-bit groups, representable as hexadecimal digits, 0-9a-f) long. Each byte of the input field of pack() generates 4 bits of the result. For non-alphabetical bytes the result is based on the 4 least-significant bits of the input byte, i.e., on "ord($byte)%16". In particular, bytes "0" and "1" generate nybbles 0 and 1, as do bytes "\0" and "\1". For bytes "a".."f" and "A".."F" the result is compatible with the usual hexadecimal digits, so that "a" and "A" both generate the nybble "0xa==10". The result for bytes "g".."z" and "G".."Z" is not well-defined. Starting from the beginning of the input string of pack(), each pair of bytes is converted to 1 byte of output. With format "h" the first byte of the pair determines the least-significant nybble of the output byte, and with format "H" it determines the most-significant nybble. If the length of the input string is not even, it behaves as if padded by a null byte at the end. Similarly, during unpack()ing the "extra" nybbles are ignored. If the input string of pack() is longer than needed, extra bytes are ignored. A "*" for the repeat count of pack() means to use all the bytes of the input field. On unpack()ing the bits are converted to a string of hexadecimal digits.
in your code
my @hex = $hexed =~ /([0-9a-zA-Z]+)/g; for (@hex){ ... pack 'H*', $_; }
a demonstration
C:\>echo abcd1234 >test C:\>more test abcd1234 C:\>od -tx1 test 0000000 61 62 63 64 31 32 33 34 20 0d 0a 0000013 C:\>hexdump test 00000000: 61 62 63 64 31 32 33 34 - 20 0D 0A |abcd1234 + | 0000000b; C:\>perl -e"print pack q,H*,, $_ for @ARGV" 61 62 63 64 31 32 33 34 abcd1234

In reply to Re: To 'pack' or 'unpack' that is the question by Anonymous Monk
in thread To 'pack' or 'unpack' that is the question by Wiggins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.