use warnings; use strict; my $username = getpwuid( $< ); my $dir = '/etc'; if($username ne "root"){ print "please run this script as root...\n"; exit; } else{ unless (-d "$dir/Automation"){ mkdir"$dir/Automation" or die $!; my $cronjob = "0 12 * * * /usr/bin/perl /etc/Automation/aptscript.pl"; open my $cron_fh, '>', 'crontab'; print $cron_fh $cronjob; close $cron_fh; open my $script_fh, '>', 'aptscript.pl' or die $!; print $script_fh '' . "#!/usr/bin/perl\n" . "print 'replace this script ...'"; close $script_fh; } }