$ cat test.pl
my $pid = 5892;
my $not = system(\"top -H -p $pid -n 1 | grep myprocess | wc -l\");
print \"not = $not\\n\";
$ perl test.pl
11
not = 0
$
Using backtick or qx helps, thanks everybody for the answers. However, I found that if you use backtick or qx, the output contains trailing newline and I need to remove that. So I used chomp.
chomp($host = `hostname`);
chomp($domain = `domainname`);
$fqdn = $host.".".$domain;
More information here: http://irouble.blogspot.in/2011/04/perl-chomp-backticks.html