#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); my $line = ; my %hash; while($line){ my ($tag1, $tag2, $tag3) = split(/\t/, $line); if ($tag2 =~/NN/) { $hash{$tag3}{frequency} = (($hash{$tag3}{frequency})+1); $hash{$tag3}{variants} = $tag1; } $line = ; } print Dumper \%hash; __DATA__ The DT the International NN International for IN for well NN well preparation NN preparation preparation NN preparation in IN in conference NN conference conference NN conference conferences NN conference good VVG good