use strict; use warnings; my @comp; # open FH in some suitable way... while() { s/^\s+//; s/\s+$//; my @flds = split( / *\t */ ); # tabs might have spaces around them if ( @flds == 5 ) { # presumably first line of pair warn "Input line $. replaces previous first-line data: @comp\n" if ( @comp ); @comp = @flds; } elsif ( @flds == 6 and $flds[5] =~ /number=(\d+)/ and $flds[0].$flds[1] eq $comp[0].$comp[1] ) { push @comp, $1; print join( "\t", @comp ), "\n"; @comp = (); } else { warn "Input line $. ignored: $_\n"; } }