if( ! $fh{$fh_token}) { open my $fh, '>', "$fh_token.txt" or die "Can't write to '$fh_token.txt': $!\n"; $fh{$fh_token} = $fh; # store filehandle } my $fh = $fh{$fh_token}; # this is the filehandle to print to