#!/bin/bash out=/tmp/wrapper.$$ perl some_script.pl > $out 2>&1 # run your script, trapping everything dest=`perl -x $0 $out` # examine logfile, figure out right place mkdir -p ${dest%/*} # make sure the directory exists mv $out $dest # move the log into place exit ############################### #!/usr/bin/perl use strict; use warnings; my $filename = $ARGV[0]; my $output; # read in $file, figure out where it should go; set $output print $output;