my %hash = ( one => "first bit", two => "second bit", ); # open files foreach my $file (keys %hash) { open $file, ">$file" or die "could not open $file: $!\n"; } # print elements foreach my $key (keys %hash) { print $key "$key => $hash{$key}\n"; }