use strict; use warnings; my $string = "0x010203"; my @in = split(//, $string); shift @in; shift @in; my $bytes = int(scalar(@in) / 2); my $output = pack('H2' x $bytes, @in); # print out the converted output, just to double check print unpack ('H2' x $bytes, $output); $output =~ s/[\x00-\x1F\xFF]/./g; # ASCII representation of hex value of byte print " $output\n"; # ASCII character for each byte