#!/usr/local/bin/perl use strict; use warnings; my $prev_key = ''; my $match_count; while (<>) { my @flds = split; my $key = join ' ', @flds[6,7]; $match_count = 0 if ( $key ne $prev_key ); $prev_key = $key; splice( @flds, 6, 0, ++$match_count ); print join( "\t", @flds ), "\n"; }