Q:

Represent first 8 characters of the string as hex numbers separated by spaces

I need to represent first 8 characters of the string as hex numbers separated by spaces.
For example:
"This is the test!" converts to "54 68 69 73 20 69 73 20"
I use the following code to do it. Is there better(simpler) way to do it in Perl?
my $hex = unpack( "H16", $string );

my $hexOut = "";
for ( my $i = 0 ; $i < length($hex) ; $i += 2 )
{
    $hexOut .= substr( $hex, $i, 2 ) . " ";
}
$hexOut = substr( $hexOut, 0, -1 );

A:

I can't resist submitting a Perl one-liner!
my $string = "This is a test";
print(join(' ', unpack("(A2)*", unpack( "H16", $string ))) . "\n");

