http://www.perlmonks.org?node_id=1034829


in reply to how to unpack a C struct with length array preceding data array

If you really want to do it in one unpack you can...

use strict; use warnings; use Data::Dumper; my @arr = unpack('(W W @0Wx/a @1W@0Wx/x/a)', "\005\006Hello World"); print Dumper(\@arr);

Which produces:

$VAR1 = [ 5, 6, 'Hello', ' World' ];

But I would never do that, except to prove that I could.