use strict; use warnings; sub run_and_log { my $aCmds = $_[0]; # things to do before doing any command # hint - if you can do it for the first command and then # treat it as already done for each of the rest, it # belongs here - example: you only need to open the log # file once for the first command. All the rest of the # commands can reuse the LOG file handle foreach my $cmd (@$aCmds) { #things that need to be redone for each command } # things to do after all commands are done # hint: these are usually cleanup tasks: e.g. closing # file handles or printing the total number of successful # or unsuccessful commands } run_and_log(\@ARGV);