use HTML::Entities qw( encode_entities_numeric ); sub handle_char { my $self = shift; my $x = shift; print encode_entities_numeric($x); }