my $previous = ''; while (<>) { @gtf = split /\s+/, $_; chomp(); # switch those two to chomp the line before you split it, # otherwise your chomp is meaningless. Also, those are # the default arguments to split: while(<>){ chomp; my @gtf = split; if ("$gtf[9]" ne "$previous") { # don't put quotes around single variables; potentially buggy if( $gtf[9] ne $previous ){ $gtf[2] =~ tr/ex*/ex1/; # this probably doesn't do what you want. # tr/// transliterates characters: here e becomes e, # x becomes x, and a literal asterisk becomes 1. # If you want to reset $gtf[2] back to 'ex1', just do so: $gtf[2] = 'ex1'; } else { $gtf[2]++; # this may bite you too. $x='ex9'; $x++; $x=='ey0' # you probably want to increment just the number: $gtf[2] =~ s/(\d+)/$1+1/e; } # now save $gtf[9] in $previous so it can be compared to the next line $previous = $gtf[9]; # here is where you would print out the array values, or do whatever you like with them }