G'day amma,
Welcome to the monastery.
I had a few issues with your example.
-
$var2 begins with a '(' (left parenthesis) but that leading character is not present in the original string at that position.
-
Should tlp_add_p0(0)) have an additional trailing ')' (right parenthesis) to match the others?
-
Using etc is a bit vague so I'm guessing here. A better way to show this sort of thing is with an ellipsis, e.g. "A, B, C, ..., Z".
-
Is the pattern 'NOT(tlp_p0(N) XOR tlp_add_p0(N))' common throughout or are there other formats?
If the repeated, internal pattern is the same throughout, you can do something like this:
$ perl -Mstrict -Mwarnings -E '
my $x = qq{tlp_p2 <= (((((((NOT(tlp_p0(0) XOR tlp_add_p0(0)) AND\n
+};
$x .= q{ NOT(tlp_p0(1) XOR tlp_add_p0(1))) AND };
$x .= q{NOT(tlp_p0(2) XOR tlp_add_p0(2))) etc};
say for $x =~ /(NOT\(tlp_p0\(\d+\) XOR tlp_add_p0\(\d+\))/gm;
'
NOT(tlp_p0(0) XOR tlp_add_p0(0)
NOT(tlp_p0(1) XOR tlp_add_p0(1)
NOT(tlp_p0(2) XOR tlp_add_p0(2)
If you want to use split, I'd chop off any leading and trailing dross then split something like this:
$ perl -Mstrict -Mwarnings -E '
my $x = qq{tlp_p2 <= (((((((NOT(tlp_p0(0) XOR tlp_add_p0(0)) AND\n
+};
$x .= q{ NOT(tlp_p0(1) XOR tlp_add_p0(1))) AND };
$x .= q{NOT(tlp_p0(2) XOR tlp_add_p0(2))) etc};
$x =~ s/\A\w+ <= \(+(.*?)\) etc\z/$1/ms;
say for split /\)\s*AND\s+/ => $x;
'
NOT(tlp_p0(0) XOR tlp_add_p0(0)
NOT(tlp_p0(1) XOR tlp_add_p0(1))
NOT(tlp_p0(2) XOR tlp_add_p0(2))
|