use HTML::Entities; my $encoded = encode_entities( $input, "&;" );