in reply to Bitwise AND with large numbers

If you want to perform a bitwise AND with a Perl integer, the first 16 or 24 "characters" of your hex string will disappear anyway, as your integer will be limited to 32 or 64 bits. So, your result is going to be:
hex(substr($hex, -8)) & $integer; # Perl with 32-bit integers hex(substr($hex, -16)) & $integer; # Perl with 64-bit integers