my ($col1, $col2); my %index = (); open INFILE, "<", "textfile.txt" or die "Can not open textfile.txt"; while ( ) { chomp; ($col1, $col2) = split (/ /); if (not exists $index{$col1}) { $index{$col1} = 1; }else{ $index{$col1}++; } close INFILE; open OUTFILE, ">", "outfile.txt" or die "Can not open outfile.txt"; foreach my $value (sort keys %index) { if ($index{$value} > 1) { print OUTFILE "$value\n"; } } close OUTFILE;