my $found_logout = 1; my $i = 0; my %hash; while ($i < @tokens) { if ($found_logout) { %hash = (date => $tokens[$i++]); $found_logout = 0; } else { my $key = $tokens[$i++]; my $value = $tokens[$i++]; $hash{$key} = $value; if ($key eq "Logout") { $found_logout = 1; do_db_stuff(\%hash); } } } sub do_db_stuff { print Dumper shift; }