while (<>) { chomp; $hash{$1}++ if /($\w+)/; } print map { "$_\n" } keys %hash;