You can do a simple concat. If you put any
print statements in the sub they will be printed before the other error message (when the sub is called). This way you don't have to screw arround with signal handlers.
sub mysub {
print STDERR "This is printed before the error message.\n";
return "\nThis is printed in the middle of the error message.";
}
open(TMPFILE,"<datafile.txt") || die "Cant open: $!" . mysub();
outputs:
This is printed before the error message.
Cant open: No such file or directory
This is printed in the middle of the error message. at temp.pl line 6.