open(OLDOUT, ">&STDOUT"); open(STDOUT, ">foo.out") || die "Can't redirect stdout"; #doing your interesting things here... close(STDOUT); open(STDOUT, ">&OLDOUT"); #here's is your starting state.