Well, something similar, yes... parse the hex characters as a binary value, then convert to base64. That uses a little bit more than 0-9 a-z A-Z, but only a few more characters. Are you okay to use three other characters in addition to those 62? You can use base64_encode
to perform the encoding if so.
(You could convert to base32 instead, but that wouldn't be as compact. Converting to bases which aren't powers of 2 is also feasible, but less appealing.)
You'd also need some way of representing a final half-byte if your input sequence had an odd number of characters. You'll probably want to think about that before calling pack
to do the original parsing...