#!env perl use strict; use warnings; open my $FH, '>', 'task_part_two.sh' or die "Can't create script 'task_part_two.sh': $!\n"; while (my $arg = shift) { print "Setting things up for task $arg\n"; # . . . do the work for the first script . . . # Create a new directory name my $the_dir = "dir_" . int(1000*rand); # build the directory and put the required file in it # Now that it's set up, write the command to run the # second script print $FH "/the/script/path.sh '$the_dir' '$arg'\n"; }