http://www.perlmonks.org?node_id=1025887


in reply to Windows Net Use

You can avoid splitting alltogether if you search for your share in the output of net use and then return the first word of that line.

use strict; my $inputDirectory = '"\\\\10.81.253.70\\file data\\query files"'; # need to dublicate each \ in string $inputDirectory =~ s|\\|\\\\|g; my @lines = `net use`; foreach my $line ( @lines ) { next unless $line =~ m|$inputDirectory|; $line =~ /(^\S+)/; print $1; }

This also overcomes the issue that the output of net use is sometimes split into two lines when it is too long. The output of net use sometime returns no status as well, which might be a problem or not.