sub hexdump($) { my $offset = 0; foreach my $chunk (unpack "(a16)*", $_[0]) { my $hex = unpack "H*", $chunk; # hexadecimal magic $chunk =~ tr/ -~/./c; # replace unprintables $hex =~ s/(.{1,8})/$1 /gs; # insert spaces printf "0x%08x (%05u) %-*s %s\n", $offset, $offset, 36, $hex, $chunk; $offset += 16; } }