{ my %handles; # Closure keeps the hash between function calls sub handle{ my $city = shift; my $temp; unless ($handles{$city}){ open $temp, ">", "$city.txt" or die "$!"; $handles{$city} = $temp; } return $handles{$city}; } }