my %state_hash; while () { chomp; my ($stamp,$state) = split/\s*\|\s*/; print "$stamp $state\n"; push @{$state_hash{$stamp}}, $state; } print "\n"; for my $stamp (sort keys %state_hash ) { print "$stamp: @{ $state_hash{$stamp} }\n"; } __DATA__ 200910021546 | Dormant 200910021546 | In Use 200910021352 | In Use 200910021352 | Dormant 200910021352 | In Use 200910021125 | In Use 200910021125 | In Use 200910021125 | Dormant #### perl stampstate.pl 200910021546 Dormant 200910021546 In Use 200910021352 In Use 200910021352 Dormant 200910021352 In Use 200910021125 In Use 200910021125 In Use 200910021125 Dormant 200910021125: In Use In Use Dormant 200910021352: In Use Dormant In Use 200910021546: Dormant In Use