in reply to silly regex question

You need the /s modifier so that . matches newlines. See perldoc perlre. But it won't match anyway, because there isn't a %> sequence before the first single quote. This version optionally matches the start of the string instead of %> and the end instead of <%:
s/ ( (?: # non capturing parens ^|%> # start of string or %> ) .* ) ' (.* (?:<%|$) ) /$1 SOMESTRING $2/gsx # add s and x modifiers
I'm not at all sure this is a good or robust solution however, and I'm looking forward to the other replies.