$inputDirectory="\\\\10.81.253.70\\G\$"; my $c = `net use`; my $unc = 0; my $h; my @a=split(' ',$c); foreach $h (@a) { if ($h eq 'OK' || $h eq 'Disconnected') { $status =$h; $temp=1; } elsif($temp == 1) { my $remote=$h; if($status eq 'OK' && $remote eq $inputDirectory) { $unc=1; } $temp = 0; } } if ($unc == 1) { print "UNC is Connected"; } else { print "UNC is Disconnected"; }