Take a look at the example in man perlfunc under the function "open".
In reply to Re: dup() in perl by leslie in thread dup() in perl by vinoth.ree