It may also be useful to check the return status of your
qx command using the special variable
$?. This may be a more portable solution since I do not get the same system message as you do when it fails. I get
"id: test: No such user".
use strict;
use warnings;
my $cmd = qx{id ahmedf 2>&1};
if ($?) {
print "Please check LDAP\n";
exit 2;
}
elsif ($cmd =~ /uid/) {
print "LDAP Ok\n";
exit 0;
}