use strict; use warnings; open(FILE, "Q.txt"); my $file = ; my @column; while () { @column=($file); chomp @column; my $number=0; while($number <= $#column) { #go through the array from 0 to the last element my $j; my $count=0; foreach ($j=$number; $j < $#column; $j++) { #select the numbers from the beginning of the line my $d=($column[$j]=~/(\d+)/)[0] - ($column[$j+1]=~/(\d+)/)[0]; #difference last if abs($d)!= 1; #if differ more than 1 - leave. $count+=$d; #accumulate the difference. } if(abs($count)>=8) { $column[$_].= " t\IN " for $number..$j; $number=$j+1; } if(abs($count)<8){ $column[$number].= " \tOUT" ; $number++; } } } print for @column; exit; #### 5 Q CAA 16 Q CAG 21 Q CAA 74 Q CAA 80 Q CAG 82 Q CAG 84 Q CAG 85 Q CAG 89 Q CAG 90 Q CAG 91 Q CAG 92 Q CAG 93 Q CAA 94 Q CAG 95 Q CAG 96 Q CAG 98 Q CAG 99 Q CAG 100 Q CAG 101 Q CAG 102 Q CAG 106 Q CAG 107 Q CAG #### 5 Q CAA OUT