In PHP it's as simple as htmlspecialchars, how to do it in Perl?
htmlspecialchars
Use the HTML::Entities module.