#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Proc::Background; my $command = 'ls'; my $arg1 = '-la'; # Add an option to kill the process with die when the variable is # DETROYed. my $opts = {'die_upon_destroy' => 1}; my $bg = Proc::Background->new($opts, $command, $arg1); my $pid = $bg->pid; say $pid; $bg = undef; __END___ $ perl test.pl 9944