while ( ) { if (/fixedStep chrom=chrX start=(.+) step=1/) { $counter = $1; } else { print "$counter\t$_\n"; $counter++; } }