open(FILE2,">file1.txt")|| warn "Could not open\n"; open(FILE3,"file2.txt")|| warn "Could not open\n"; my $Previous = ""; my @data = ; $index=0; foreach $_data (@data) { $index++; chomp ($_data); @Current = split(/\t/, $_data); @Previous = split(/\t/, $Previous); if (@Current[0] ne @Previous[0]) { if ($index == 1) { # do nothing. } else { print FILE2 $Previous; } } else {} $Previous = $_data; } close(FILE2); close(FILE3);