... use Digest::SHA1 qw/sha1/; # cache for file handles; my %fh = (); my %seen = (); while () { next unless /^(\d{2})/; # ignore lines starting with anything else than 2 digits next if $seen{sha1($_)}++; # ignore if a line comes again .... ...