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,"## 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.