my $HashKey = $_[4]; $HashKey += 1; # initialise the hash my %LogHash = (); while (){ if (/\b$Autosys/) { # populate the hash %LogHash = ($HashKey => $SentRec = substr($_, 0, 20)); } } # debugging stub # print out the contents of the hash foreach $k (keys(%LogHash)) { print LOGFILE $k, ",", $LogHash{$k}, "\n"; }