sub netUse { my @net_use_output; my $output; chomp $_[0]; $_ = $1 if($_[0]=~/(.*)\\$/); print "\nnet use \* \"$_[0]\""; #my $output = `net use \* \"$_[0]\" 2>&1|`; open TASK, "net use \* \"$_[0]\" 2>&1|" or die "cannot map $_[0]"; while () { print "\n"; print; #chomp; #chop; push (@net_use_output, $_); #return $_; } print join(", ", @net_use_output); print "\n"; print "\n"; print "-----\n"; print @net_use_output[0]; $output = $2 if(@net_use_output[0]=~/^(Drive\s)([A-Z])\:(.*)$/); print "\n"; print "\n"; print "-----\n"; print $output; #return @net_use_output; } #### net use * "\\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHARS\SHARE\NAME\DOWN\DEEP" Drive S: is now connected to \\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHARS\SHARE\NAME\DOWN\DEEP. The command completed successfully. Drive S: is now connected to \\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHARS\SHARE\NAME\DOWN\DEEP. , , The command completed successfully. , ----- Drive S: is now connected to \\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHARS\SHARE\NAME\DOWN\DEEP. ----- S