in reply to Bitmask or Named permissions

Perl has powerful stringwise bit fiddling...use it. The below example allows for variable length bitstrings. If you can make sure they are all the same length (e.g. initialize to "\0"x(MAXBITS/8), then set bits), you can use eq and ne, which might make for clearer code.
sub setpermbybitnum { my $vec=""; vec($vec,shift,1) = 1; $vec } # check if any perms are set sub no_perm { "$_[0]" =~ tr/\0//c == 0} # check if all specified perm(s) are set sub has_perms { no_perm( ("$_[0]" & "$_[1]") ^ "$_[1]") } # check if any specified perms are set sub one_or_more_of_perms { !no_perm("$_[0]" & "$_[1]") } use constant READ_PERM => setpermbybitnum(3); use constant WRITE_PERM => setpermbybitnum(2); use constant EXECUTE_PERM => setpermbybitnum(1); my $allowed = READ_PERM | WRITE_PERM; # Check for permissions: if ( no_perm($allowed) ) { print "PERMISSION DENIED\n"; exit -1; } if ( has_perms($allowed, READ_PERM) ) { print "READ Allowed\n"; } if ( has_perms($allowed, WRITE_PERM) ) { print "WRITE Allowed\n"; } if ( has_perms($allowed, EXECUTE_PERM) ) { print "EXECUTE Allowd\n"; } if ( has_perms($allowed, READ_PERM|WRITE_PERM ) ) { print "READ and WRITE Allowed\n"; } if ( has_perms($allowed, READ_PERM|EXECUTE_PERM) ) { print "READ and EXECUTE Allowed\n"; } if ( one_or_more_of_perms($allowed, READ_PERM|EXECUTE_PERM) ) { print "READ or EXECUTE Allowed\n"; }