The standard idiom is:
s/([[:^ascii:]])/ sprintf '%02x', ord $1 /eg; [download]
In reply to Re: hex in regexp by jwkrahn in thread hex in regexp by shamanoff