How to sudo to another user to run command in perl

Scnario:

You need to run the script from User ABC and in the script you have to sudo to User DEF to run command.

Net::SSH::Perl enables you to simply and securely execute commands on remote machines, and receive the STDOUT, STDERR, and exit status of that remote command. It contains built-in support for various methods of authenticating with the server (password authentication, RSA challenge-response authentication, etc.). It completely implements the I/O buffering, packet transport, and user authentication layers of the SSH protocol, and makes use of external Perl libraries (in the Crypt:: family of modules) to handle encryption of all data sent across the insecure network

http://search.cpan.org/~schwigon/Net-SSH-Perl-1.35/lib/Net/SSH/Perl.pm

Solution:

## The Script is run with user ABC 
## Here you will sudo to user DEF (login as 'DEF' user)
print "Connecting as DEF user...\n";
my $ssh=Net::SSH::Perl->new($yourhost, debug=>1, protocol=>'1,2');
$ssh->login("DEF",$DEFpasswd);
## as 'DEF' user to provide 777 permission to directories
$ssh->cmd("mkdir -p /u01/def/");
$ssh->cmd("touch "/u01/def/def.txt);
## here it will return back to user ABC

Pls. note, you need to use below directive,

use Net::SSH::Perl;