open my $ps => "ps ax |" or die; my $pid; while (<$ps>) { if (/^\s*(\d+).*\bprogramname\b/) { $pid = $1; last; } } close $ps or die;