in reply to telnet smtp-

system waits for the child program to finish before it continues. So your idea won't ever work.

Just use MIME::Lite and be done with it. Hand-rolling SMTP-code is a thing of the past. Also, consider very, very carefully whether you want to accept data from a CGI, as that will likely open many venues to send spam through your machine.