in reply to Capturing the output of nmap from within a Perl script
Nmap::Scanner will do all this for you.