perl -pe"s/0x((?:[0-9a-fA-F]{2})+)/pack 'H*', $1/ge" file #### while (<>) { s/0x((?:[0-9a-fA-F]{2})+)/pack 'H*', $1/ge; print; }