use strict; my $joboutputfile = "/tmp/joboutputfile.out"; my $stuff; #run job qx!ls -al /var > $joboutputfile!; ( -e $joboutputfile ) && &checkerror; print $stuff; sub checkerror { return $stuff = qx!grep "spool" $joboutputfile!; }