in reply to Closing all filehandles associate with an fd

There's no simple way to close all files. You can try:

use POSIX; POSIX::close($_) for (0..1024);
Also exec(3) will close most of the fds

Update: also read how to close all files

Also this should be POSIX::close