#! /usr/bin/perl use strict; use warnings; use Fcntl qw( :mode ); # other code here... my $file = "/tmp/su.cmds"; open (CMDS, ">$file"); print CMDS "#! /bin/bash\n"; print CMDS "command 1\n"; print CMDS "command 2\n"; close CMDS; chmod S_IRWXU | S_IXGRP | S_IXOTH, $file; system ("sudo superuser $file"); # script continues