# the state you start from %state=(root=>1,some=>0); # let's get P(other|root,!some) $i=0; for @{$nodes{other}{parents}} { $i=($i<<2)+$state{$_} # this is a simple encoding. Just use the same for updating and accessing } $prob=$nodes{other}{probs}[$i];