http://www.perlmonks.org?node_id=964834


in reply to Removing space at end of field and converting to text

This might work for the first problem:

$field =~ s/(?:\\n)+$/<br\>/;

EDIT: Forgot to note that this only works if your newline characters really are being seen at that point as \\n and not simply \n.

As for your second question, I suspect there may be a CPAN module that could help, but don't know of one specifically...