my ($key, $msg, $ref); # stick with the naming convention ;-) foreach $key (keys %hash) { $ref = \$hash{$key}; foreach $msg (@Messages) { if ($ref->{error_message} =~ /$msg/ and $ref->{date} =~ $DATE) { # # Notice one print call will suffice, # just line up what you want to print, # or concatenate into a single string. # print RPT "$ref->{packet_id}\t$ref->{origin}\n", "$ref->{date}\t$ref->{qualifier}\n", # etc.