if ( $linkList->[$x] =~ [pattern of the server that needs authentication] ) { print("You're in the LogonUser block!"); LogonUser( '[username goes here]', '', '', 0x000003, 0x000000, $ph ) or die $^E; # ImpersonateLoggedOnUser($ph); }