#!/usr/bin/perl use warnings; use strict; my $mask_input = '0000000000'; my $lastEnd = 0; while () { my (undef, $start, $end) = split '\s+'; my ($from, $length) = ($lastEnd, $start - $lastEnd); $length-- if $length > 0; substr($mask_input, $from, $length) =~ tr[\x00-\xff][N]; $lastEnd = $end; } substr($mask_input, $lastEnd) =~ tr[\x00-\xff][N]; print "# Desired: 000N00N00N\n"; print "# Obtained: $mask_input\n"; print $mask_input eq '000N00N00N' ? "OK" : "Wrong", "\n"; __DATA__ chrX 1 3 chrX 5 6 chrX 8 9