use List::Util qw( first ); sub available { my $prog = shift; first { -x "$_/$prog } grep { m/\S/ && -d } split m/:+/ => $ENV{PATH}; }