$bitfield = .... my @fields = ( $modifier =~ m{ ([+-]) (\d+) }gxms ); # extract mods while ( @fields >= 2 ) { # for each modification my $op = shift @fields; my $value = shift @fields; if ( $op eq '+') { $bitfield |= $value; # set a bit w/ OR } elsif ($op eq '-' ) { my $dummy; # no-op to force full-width $dummy = sprintf "%064b\n", $value; my $negated = ~$value; $trade_condition &= $negated # clear a bit w/ negated AND } }