in reply to A Reg Exp Question

Like swiftone said, for the general case you really want a full-blown parser. But if you can narrow the possibilities, a regex solution may work.

My first assumption would be that all the print statements you want to eliminate are contained in a single line. This seems to be the case from your example. In this case, I would suggest processing line-by-line instead of joining the whole thing in a single string and processing that.

My second assumption would be that the prints you want to eliminate will have one of the following forms:

print "string" print("string") print HANDLE "string" print(HANDLE "string")
where spacing can be arbitrary, handles are always all-uppercase, and the string does not contain double quotes.

Given this, I would do something like the following:

while(<FILE>) { s/print(\s+|\s*\(\s*)([A-Z]+\s+)?"string"(\s*\))?/1/; print; }
This is untested. Notice that I am substituting the print statement with a 1, so that it does not break things like:
print "string" if (somecond) becomes 1 if (somecond) something if print HANDLE "string" something if 1 etc.

--ZZamboni