#!/usr/opt/perl5/bin/perl use strict; use warnings; use Data::Dumper; my %earliest; my %latest; my %hash_of_arrays; my $line; while ($line = ) { chomp $line; # remove return my ($key, $date) = split /\s+/, $line, 2; # split on space into max 2 parts next unless $date; # ignore blank or malformed lines unless (defined $earliest{$key}) { $earliest{$key} = $date; } $latest{$key} = $date; # or with a hash of arrays $hash_of_arrays{$key} or $hash_of_arrays{$key}[0]=$date; $hash_of_arrays{$key}[1]=$date; } print Data::Dumper->Dump([\%earliest], ['%earliest']) ; print Data::Dumper->Dump([\%latest], ['%latest']); print Data::Dumper->Dump([\%hash_of_arrays], ['%hash_of_arrays']); print "first time for KEY1 was: $hash_of_arrays{KEY1}[0]\n"; print "last time for KEY1 was: $hash_of_arrays{KEY1}[1]\n"; __DATA__ KEY1 07/25/05 09:04:36 KEY2 07/25/05 09:04:36 KEY2 07/25/05 09:04:37 KEY2 07/25/05 09:05:49 KEY2 07/25/05 09:05:50 KEY3 07/25/05 09:05:50 KEY1 07/25/05 09:06:36 # output =>./first $%earliest = { 'KEY2' => '07/25/05 09:04:36', 'KEY1' => '07/25/05 09:04:36', 'KEY3' => '07/25/05 09:05:50' }; $%latest = { 'KEY2' => '07/25/05 09:05:50', 'KEY1' => '07/25/05 09:06:36', 'KEY3' => '07/25/05 09:05:50' }; $%hash_of_arrays = { 'KEY2' => [ '07/25/05 09:04:36', '07/25/05 09:05:50' ], 'KEY1' => [ '07/25/05 09:04:36', '07/25/05 09:06:36' ], 'KEY3' => [ '07/25/05 09:05:50', '07/25/05 09:05:50' ] }; first time for KEY1 was: 07/25/05 09:04:36 last time for KEY1 was: 07/25/05 09:06:36