Consider using a web services protocol like
XMLRPC::Lite - this makes it easy to pass Perl data structures ( at least the simpler ones ) from a CGI script to the daemon and back.
The messages get passed as HTTP requests, and they are human readable, so debugging is made simpler.