#!/usr/bin/perl $| = 1; open(OUT, ">foo"); &CloseAllOpenFiles(); print "done with close.\n"; sleep 20; # go look at process with lsof to see if fd still open sub CloseAllOpenFiles { local *F; for (my $fd=0; $fd<=1024; $fd++) { open F, "<&=$fd" or warn "Cannot reopen fd=$fd: $!"; close F; } }