use IO::File; my %files; $files{A} = $files{B} = $files{C} = IO::File->new('> groupA.txt'); $files{D} = $files{E} = $files{F} = IO::File->new('> groupB.txt'); # etc... for my $n (keys %emp) { print {$files{$n}{Org}} $emp{$n}{Emp}; # ^^^^^^ ^^^^^ # This gets the FH And prints this to it } # Now close the FH's close($file{$key}) for my $key (keys %files);