use List::Util qw/any/; ... # if ($A+$B == 2 && grep {$_ eq $TI} @IDS){ if ($A && $B && any { $_ eq $TI } @IDS) {