use Data::Dumper; use strict; my $hash = {}; my @files = ( "LOG1", "LOG2", "LOG3" ); foreach my $file ( @files ) { open FILE, "<", $file or die "Unable to open $file\n$!\n"; my ( $date, $id, $timestamp ) = qw( Unknown "" "" ); while () { chomp; if (/^\d/){ $date = $_; } elsif (/^\s+ID\s*=\s*(.*)$/) { $id = $1; } elsif ( /^\s+TIMESTAMP\s*=\s*(.*)$/ ) { $timestamp = $1; } elsif ( /^\s+COUNT_\d+\s*=\s*(.*)$/ ) { $hash->{$date}->{$id}->{$timestamp} += $1; } } } print Dumper($hash), "\n";