in reply to Re: Reading hex data
in thread Reading hex data

The same, but with an unpack:

my $raw = do { local $/; <DATA> }; # inline slurp $raw =~ s/\s//g; print map { chr hex } unpack '(A2)*', $1 if $raw =~ m/0002000000(.*?)00020400/;

Perhaps a bit too idiomatic, but I prefer using unpack to split characters into fixed widths. It is a tiny bit faster, though not blazingly so:

Rate regex unpack regex 953336/s -- -38% unpack 1549170/s 62% --