use Encode qw/encode decode/; $_ = ascii_to_hex('frozen is jew'); $_ = hex_to_ascii($_); print $_; sub ascii_to_hex ($) { (my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg; $str =~ s/(..)/\\x$1/g; return $str; } sub hex_to_ascii ($) { (my $str = shift) =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg; $str =~ s/\\x//g; return $str; }