use HTML::Entities; my $html = "bad stuff here"; $html = encode_entities($html, "\x80-\xff");