in reply to efficiently printing to 30 files

tbone,
There is a command in Unix called tee which allows you to pipe your output to two different locations. IO::Tee is a CPAN module that allows you to select multiple locations. I do not know if it is any more efficient from a speed perspective as I haven't looked under the hood, but it certainly would be more efficient in programming time.

Hope this helps - cheers - L~R

Update: Ok so I am sick with the flu and I misread "one of 30 files" to be 30 files. So now what can I offer since all kinds of people have replied with applicable solutions?

allolex suggested using subs for repeated pieces of code. I would suggest using a sub for a different reason.
You could use one sub to open all the files and another sub to determine which file handle to select based off the data and then just use print in the main code.

#!/usr/bin/perl -w use strict; # Some code to build your complex hash OpenFiles(); foreach my $n (keys %emp){ my $print = CheckData($n); if ($print) { select $print; print $emp{$n}{'Emp'}; } } sub OpenFiles { mkdir "reports", 0755 || warn "Cannot make reports director: $!"; chdir ("reports") || die "couldn't change to directory : $!"; # All the open statements } sub CheckData { return "A" $emp{$_[0]}{'Emp'} if $emp{$_[0]}{'Org'}=~/ABC/; # etc }

Obviously this code could be cleaned up a bit, but I felt bad for having misread your post and not providing anything useful. With a little work - you pass two arguments to your sub, one is the value to check and the other determines which type of check to perform. This way you could do more than just check the 'Org' value.

Cheers - L~R