Actually, you should have gotten
in reply to Using Perl Regex to find & replace large chunks in code
which can be used as follows:
perl -i~ -0777p sub.pl *.cstol
-0777 causes the whole file to loaded into $_.
Update: Oops, that command is the same as you gave. I've just tested it and it works. Perhaps you didn't have a newline after the last endif?