my $ssh = Net::OpenSSH->new(...); for my $cmd (@cmds) { $ssh->system('sx', 'su', '-l', $user, '-c', $cmd); }