use HTML::Entities; # Insert much code here my $escaped_html = encode_entities($raw_html); # Insert the rest of your program