$str = '( (1 == 1) and (2 < 1) ) or (2 > 0)'; while ($str =~ s/(\([^()]+\))/qq($1 || 0)/ee) { print eval($1) ? 'ok' : 'error'; print ": $1\n"; }