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;