use strict; use warnings; my %dates; while () { next unless /(.)(..)(..)(.{4})/; my $date = "$4$3$2"; if (exists $dates{$date}) { print "$date - Hash exists\n"; # play with hash } else { print "$date - Hash doesn't exist\n"; # create the hash $dates{$date} = undef; # play with hash } } __DATA__ x11112007 y11122007 p11112007 x11132007 #### 20071111 - Hash doesn't exist 20071211 - Hash doesn't exist 20071111 - Hash exists 20071311 - Hash doesn't exist