質問です。現在FreeBSD上で、マニュアルページをHTMLに変換するCGIを書いていて、文字化けに困っています。
プログラム名は test.cgi です。手元で、% ./test.cgi > log として、出力されたログを見ると、きちんと
EUC-JPで出力されているのですが、ブラウザでアクセスしたり、fetch コマンドでアクセスしたり、telnet で
直接WebServerと話したり、とにかくApache を通すと、日本語の部分が、&xxx; と、文字実体参照の形に
なってしまいます。どうすれば文字化けを無くせるでしょうか。

(余計な部分を切り詰めた)プログラムを貼ります。

#! /usr/local/bin/perl -w
binmode(STDOUT, ":encoding(euc-jp)");
$filename= "/usr/local/man/ja/man3/strlen.3.gz";
$command = "gzcat $filename | /usr/local/bin/groff -man -Thtml -dlang=ja_JP.eucJP";
open(PIPE, "-|:encoding(euc-jp)", "$command") or die;
@html = <PIPE>;
close(PIPE);
print "Content-type: text/html; charset=euc-jp\n\n";
for $text (@html) {
  print $text;
}