I don't know Perl very well, but my guess is that the first program is one that should be spawned by the webserver and communicates via pipes. Read the
CGI and FastCGI HOWTO if you don't know what that means. If I'm correct about that, you could indeed use the cgi-fcgi tool.