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