my $flag=0; # or value from your api vec($flag, $bitNames{BIT0}, 1)=$newBit; # you can also use vec to retrieve the old bit values: print "Value at position BIT3 is:",vec($flag, $bitNames{BIT3},1),"\n";