use Encode qw/encode decode/; $_ = ascii_to_hex('\x66\x72\x6f\x7a\x65\x6e\x20\x69\x73\x20\x6a\x65\x77'); $_ = hex_to_ascii($_); $_ = 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; }