So I hear two votes for using a proper parser and several piecewise suggestions that, unfortunately, don't lend themselves to transforming the entire file in one substitute.
I was hoping there might be some trick like
$programSource =~ s/in \(('([^']*)'[,])*\)/=~ m#[$2$3$4$5$6$7$8$9]#;/g;
where perhaps the outer group of parentheses would be $1 and any number of nested inner parentheses groups would be matched for all patterns matching ([^']*) inside the single-quotes. In a more broken-out fashion:
$programSource =~ s/in \(
(' <-- outer group start goes in $1
([^']*) <-- inner group chars between ''
'[,])* <-- followed by optional comma, close outer group
+ and repeat outer group for any number of repetitions
\)/=~ m#[$2$3$4$5$6$7$8$9]#;/g; <-- put inner grou
+ps in match (up to 8 of them, anyway)
Since I'm trying to use global substitutes that can span several lines and update the entire source file in one substitutution, and since there are only three cases in the source I am currently trying to transform, I'll probably just use three separate global substitutes, one for each of the
in ('X'),
in ('X','Y') and
in ('X','Y','Z') cases. It just seems like it ought to be something one could do with a single fancy global substitute.
Thanks for your thoughts.