package html; require Tie::Handle; @ISA = qw/Tie::Handle/; use HTML::Entities; sub TIEHANDLE { return bless({}, shift); } sub PRINT { untie *STDOUT; print encode_entities(join "", @_); tie *STDOUT, "html"; } package main; tie *STDOUT, "html"; print "foo & bar\n";