use strict; use warnings; while () { chomp; s/^\s+//; s/\s+$//; my @tokens = split /\t/; if ((scalar @tokens) == 5) { print $_; } elsif ((scalar @tokens) == 3) { if (/number=(.*)/) { print "\t$1\n" } } } # not sure how many tabs you have in your 2nd line __DATA__ Chr21 NT_113958 STS 76092 76265 Chr21 NT_113958 number=1