use Math::BigInt;
my $switchPortNumber = 2;
# 32 Character hex string from switch
my $hexstring = Math::BigInt>new('0x40000000000000000000000000000000'
+);
my $mask = (Math::BigInt>new('0x80000000000000000000000000000000') >>
+ $switchPortNumber);
my $result = ($hexstring & $mask) > 0;
Another approach would be to turn it into an ASCII bitstring, in which case you can use a simple substr() instead of the AND masking
my $bitstring = unpack('B*', pack('H*', '40000000000000000000000000000
+000'));
my $result = substr($bitstring, $switchPortNumber, 1) eq '1';
