我解决了这个问题。
#!/usr/bin/perl
use strict;
use warnings;
use FCGI;
use Socket;
my $socket = FCGI::OpenSocket(":9000", 5);
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket);
my $count = 1;
while($request->Accept() >= 0) {
print "Content-Type: text/html; charset=UTF-8\r\n\r\n";
print $count++, "<br />";
print "$$<br />";
open(my $client, "+>&4") or die "$!";
my $mysockaddr = getsockname($client) or die "$!";
my ($myport, $myaddr) = sockaddr_in($mysockaddr);
print $myport, ":", inet_ntoa($myaddr), "<br />";
my $peersockaddr = getpeername($client) or die "$!";
my ($peerport, $peeraddr) = sockaddr_in($peersockaddr);
print $peerport, ":", inet_ntoa($peeraddr), "<br />";
close $client;
}