{ my %entity_for = qw{& & < < > >}; sub chars_to_ents { $_[0] =~ s/([&<>])/$entity_for{$1}/gr } }