in reply to RegEx Confusion!

The following assumes that the packet is in a stream of 1's and 0's.
my $flag1 = substr $packet, 0, 8; my $byte_count = substr $packet, 9, 16; my $num_bytes = convert_byte_count($byte_count); my $payload = substr $packet, 25, $num_bytes * 8; my $flag2 = substr $packet, 25 + $num_bytes * 8, 8;
The definition of convert_byte_count() is left as an exercise for the reader.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.