my $command = pop @ARRAY; while (shift @ARRAY) { die ("Error: " . $!) unless -e; } # run your command here -- exec $command, I assume