#!/usr/bin/perl warn "\n==normal case:\n"; print "running ls:\n"; system( "ls" ); open my $oldout, ">&STDOUT"; # "dup" the stdout filehandle close STDOUT; warn "\n==STDOUT closed:\n"; print "running ls a 2nd time\n"; system( "ls" ); open STDOUT, '>&', $oldout; # restore the dup'ed filehandle to STDOUT warn "\n==STDOUT reopened:\n"; print "running ls a 3rd time\n"; system( "ls" );