in reply to checking external program for availability?

Incase you didn't notice in the first post using grep, the -x function tests whether a file is executable. Like so:
if ( -x '/path/to/file' ) { # file is executable, run it system('/path/to/file'); } else { # whatever system('/run/something/else'); }