sub hexdump { my $s = shift; print join " ", unpack("(H2)*", $s), "\n"; } # ... hexdump($x);