in reply to reverse engineer a filehandle

Best way is to store a hash of both the filehandle and its name:

use strict; use warnings; use Data::Dumper; sub openRandom { my $fh = { name => (int rand 1000) . '.txt' }; return $fh if open($fh->{'handle'}, ">$fh->{'name'}"); } print Dumper(openRandom());