in reply to Safer (and cleaner) way to print user-supplied text.

Would HTML::Entities do what you're asking?
use HTML::Entities; my $encoded = encode_entities( $input, "&;" );
The second argument provides the "unsafe" characters that you want encoded. perldoc HTML::Entities.