in reply to splitting data

If you do not care about balanced parantheses it is simple:

use strict; use warnings; my $tlp_p2 = "(((((((NOT(tlp_p0(0) XOR tlp_add_p0(0)) AND NOT(tlp_p0(1) XOR tlp_add_p0( +1))) AND NOT(tlp_p0(2) XOR tlp_add_p0(2)))"; my @var = split /\s*AND\s*/, $tlp_p2; $,="\n"; print @var;

BUT: already your proposed split for $var1 and $var2 does not have balanced parantheses. In fact, the closing ) at the end of $var2 corresponds to the opening ( at the beginning of $var1 if I have counted correctly. How do you want to deal with that situation?

Remark: If the terms in your equation are always of this type, you can create them bottom-up easily instead of extracting them from the equation...