You say you have two columns:
1) 'gene id'
2) length of 'gene id'
This part in your question i do not understand, probably because my knowledge of English language: '... of among various transcript id ...'
How does 'transcript id' relate to 'gene id'?
Why do you want to solve this in Perl, (or why will you not solve this in Excel)