in reply to Converting case in a replacement

In addition to jeffa's solution, there are (at least) two other ways you can do this task:

You appear to not be using warnings, a good idea. If you were using warnings, you would get the warning, "\1 better written as $1". (Either that, or you're using a very old version of perl -- please upgrade.) </p.

Also you probably want to add the /m ("multiple lines") option to your regex. As described in perlre, it is required for $ to match any end of line in the string, not just one at the end of string.