I don't have a similar set-up as yours so I cannot test your code and therefore I can only give some general pointers.
- Add use strict; and use warnings; and change your code so it runs without complaints under these pragma's.
- use indirect filehandles in the three-argument form of open: open(my $IFILE, ">", $file"); rather than open(IFILE, ">$file"). These filehandles close by themselves when they fall out of scope. Of course there is nothing wrong with explicitly closing a filehandle once you are done with it.
- You declare lexical variables (which is Good), but then undef them only to redeclare them a few lines later. Probably you want to make sure that you start with fresh variables, but OTOH you initialize these lexical variables when you declare them! You could dispense with the undef and the second declaration and just keep the initialisations.
- Test all open and close functions for errors. As a general rule, test everything which depends on an event outside your own script (this includes all OLE-calls!).
- Check the file-length immediately before you start sending it to the client. If it is still zero-length, there was something wrong with the writing of the temporary word-file. Perhaps it was not yet flushed to the disk. Wait a moment and check again. If the file remains at zero length, the OLE-call to write the Word-file did not work.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law