my %hash_sorted_by_day; for my $line (@logfile) { my %tmphash; my ($logdate, $logtime, $logip, $logsid, $logtype, $logmsg) = $line =~ m/([\d-]{10}) # date \s # _blank ([\d:]{8}) # time \s-\s # _divider ([\d\.]+) # IP \s-\s # _divider SID:([a-zA-Z0-9]{32}) # sid \s # _blank \[([A-Z]+)\] # LogType \s # _blank (.*)/xms; # message $tmphash{'time'} = $logtime; $tmphash{'ip'} = $logip; $tmphash{'type'} = $logtype; $tmphash{'msg'} = $logmsg; my @tmparray = defined $hash_sorted_by_day{$logdate}{$logsid} ? @{$hash_sorted_by_day{$logdate}{$logsid}} : () ; push (@tmparray, \%tmphash); $hash_sorted_by_day{$logdate}{$logsid} = \@tmparray; };