I'm using regular expression (REGEX) to do this conversion. Below is the code.
## Initial string
$string = "abcdefjhijklmnopqrstuvwx";
## convert each character from the string into HEX code
$string =~ s/(.)/sprintf("%x",ord($1))/eg;
The above code will convert the provided string string into it's corresponding HEX code. Using regex i'm picking up the each character from the string, and get the ascii code using ord() function. Then using sprintf() I've just printed as HEX code.
If you want the output as UPPERCASE, you'll just need to make %x into %X inside your sprintf() function.
$string =~ s/(.)/sprintf("%X",ord($1))/eg;
The output will be as below for Lowercase, and Upper case:
The reverse one is at http://icfun.blogspot.com/2009/05/perl-convert-hex-string-into-character.html