in reply to Counting open files?

You can probably get what you need from the lsof utility.

my $cpid = open my $lsof, '-|', '/usr/sbin/lsof', '-g', $$, @other_opts or die $!;
Without other options to narrow the list you'll get lots of irrelevant listings, including shared C libraries, the perl executable, and the terminal you're on.

After Compline,
Zaxo