Simple, this is about math, not Perl. There is no need to parse the bits, in order to test and see whether certain bits are ones or zeroes:
To test whether certain bits are 0’s, just make up a mask with 0’s for those bits you concern, and 1’s for the rest. Bit or your mask with whatever under testing, if the value you get back is the same as the mask, you are okay.
To test whether certain bits are 1’s, just make up a mask with 1’s for those bits you concern, and 0’s for the rest. Bit and your mask with whatever under testing, if the value you get back is the same as the mask, you are okay.