Arduino environment bug interferes with serial read using PERL

Pulled my hair out for a full day. I could not get the serial data to read back using any of the code examples.
I'm using an Arduino Mega2560 and communicating with PERL on a Win-XP machine. I've been able to write to the board all day long, but could not read from it... until... a) turned on the Serial Monitor within Arduino environment, b) attempt to run my PERL script (which errors out), c) close the Serial Monitor, d) re-run the PERL script. At this point the serial transmission is available to the PERL script and the programs communicate and work flawlessly.... That is, until I reload the Arduino code on the Mega 2560. Then I have to go through the "a" to "d" process again. To me this looks like a bug in the Arduino environment that captures the incoming serial data when it is not supposed to. Or maybe there is a setting that I don't know about.

To me this looks like a bug in the Arduino environment that captures the incoming serial data when it is not supposed to

Nope. Can't be. With Windows, serial ports are opened for exclusive access (which is why having the Serial Monitor open results in an error). If the Arduino IDE was "capturing the incoming serial data" then your Perl script would error out in the same way it does when Serial Monitor is running.

The problem is either with your Perl code or with the Perl run-time.