use warnings; use strict; use 5.010; my @pos; while(){ my( $chr, $start, $end ) = split; $pos[ $_ ]++ for $start .. $end; } for my $pos ( 0 .. $#pos ) ){ next unless defined $pos[ $pos ]; say $pos,"\t", $pos[ $pos ]; }