#! perl -slw use strict; my @data = map{ [ split "','", substr( $_, 1, -2 ) ] } ; my $mask = ' ' x 10_000; # Make a blank string that's 'big enough' my $max = 0; # we'll trim it back later for( @data ) { #calc the length of the range my $len = $_->[2] - $_->[1] +1; # overwrite the range with 'xx's substr( $mask, $_->[1], $len ) = 'x' x $len; # Remember the highest offset $max = $_->[2] if $_->[2] > $max; } $mask = substr( $mask, 0, $max ); # Trim to length my $coverage = $mask =~ tr[x][x]; # Count the 'x's printf "cover = %.1f%% \n", $coverage / length($mask) *100; __DATA__ 'NM_176827','618','710' 'NM_176827','621','710' 'NM_176827','622','692' 'NM_176827','629','710'