open(my $fh, '-|', 'nmap', $ip); ## may not be supported in your version of Perl, so ## also consider the equivalent: ## open(my $fh, '-|') or exec 'nmap', $ip; my $data = do { local $/; <$fh> }; close $fh;