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


in reply to Trouble with Transliterate Function

my $mask_input = <INPUT>; ... my $lastEnd = 1; while ( <INTERVAL> ) { my (undef, $start, $end) = split '\s', $_; ## change everything from the end of the last range ## to the start of this range to 'N' substr( $mask_input, $lastEnd, $start ) =~ tr[\x00-\xff][N]; $lastEnd = $end; } ... print OUT "$mask_input";

Another way to do that:

chomp( my $mask_input = <INPUT> ); my $new_mask = 'N' x length $mask_input; ... while ( <INTERVAL> ) { my ( undef, $start, $end ) = split; --$start; substr $new_mask, $start, $end - $start, substr $mask_input, $star +t, $end - $start; } ... print OUT "$new_mask\n";