in reply to how do I shorten code

Why is it important to shorten the code? The path to mastery says a lot about this, most of it true?

More important than shortening the code above is learning the important of including full information in error messages as described in perlstyle. Also include them on every system command - including every open. It is also good to get in the habit of strict.pm and declaring your variables.

None of these will shorten your code. All will improve it. And that is more important.