my %hits; while( <> ) { my( $key ) = /HIT:\s+(\S+)/; $hits{ $key }++; } my @distinct = keys %hits;