#!/usr/bin/perl my $prog = shift || die "no args!\n"; my @pids; open PH, "ps ax|" or die $!; while( ){ /$prog/ || next; /^\s*(\d+)/ and push @pids, $1 } # Updated (thanks to merlyn): kill 15, $_ for@pids; sleep 5; kill 2, $_ for@pids; sleep 5; kill 9, $_ for@pids;