++ for pointing out the B vs b concern, but you're wrong about vec. And that code is an eval $REDFLAG;, you should do it thusly:
my ($ver, $hlen, $tos, $len) = map pack "B*", unpack "A4A4A8A16", unpack "B*", $foo;
However, that will not honour the network byte ordering in $len.