in reply to open failure code
In addition to the useful advice you've got so far, I would like to point out that programming with flag variables is not always a good idea.
See this discussion on flag variables for more material on this subject.
HTH
In Section
Seekers of Perl Wisdom