open( my $SAVE_OUT, ">&", STDOUT ); open( STDOUT, "> $POST_FILE" ) || die "Can't redirect stdout"; #more code goes here ... #end of the subroutine: #need to restore STDOUT(!?) close(STDOUT); open( STDOUT, ">&", $SAVE_OUT );