http://www.perlmonks.org?node_id=835415


in reply to extract relevent lines according to array

You try the following script to do it.
use strict; use warnings; use Data::Dumper; my $chrom='chr1'; my $start=9839; my $stop=9841; my %hash=(); my @values=(); while(<DATA>) { if(/[a-z]+\s*chrom=$chrom/) { while(<DATA>) { if(/([0-9]+)\s*([0-9]+\.[0-9]+)/) { $hash{$1}=$2; } else { last; } } } } for ($start .. $stop) { push @values,$hash{$_}; } print @values; __DATA__ variableStep chrom=chr1 9837 0.010 9838 0.008 9839 0.007 9840 0.004 9841 0.002 9842 0.001 variableStep chrom=chr2 9837 0.090 9838 0.038 9839 0.017 9840 0.044 9841 0.052 9842 0.091