my $h = "ff00f0fe"; # just 32 bits here, but any other length possible my $b = unpack("B*", pack("H*", $h)); print "$b\n"; # 11111111000000001111000011111110 my $idx = 5; my $allowed = substr($b, $idx-1, 1) eq "1";