in reply to formatting my html output

Well it's obvious the problem is on line 17. See How (Not) To Ask A Question.

Also look at [:upper:] and [:lower:] in perlre which should be locale-aware given the proper setup.

The cake is a lie.
The cake is a lie.
The cake is a lie.