input file looks like this: 0000000NNNN00NNN0NNN0N0N0NN0N #------------------------------------------------- my $population = "all28_males"; my $count = 0; my $position = 0; my ($n, $data, @info, $info, $buf); my $filtered_sites = "/Users/logancurtis-whitchurch/Dropbox/thesis_folder/galaxy_chrX_data/filtered_chrX_rawdata.interval"; open (INTERVAL, "<$filtered_sites") or die "can't open $filtered_sites"; open(MASK, "/Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/filtered_mask_files/filtered.mask."."$population".".txt") or die "can't open masked file\n"; my $mask = ; chomp ($mask); for each (my @interval = ); { chomp (@interval); my @positions = split(/\t/, $interval[$count]); my $start = $positions[1]; my $end = $positions[2]; while (($n = read MASK, $data, 100000) != 0) { my @info = split(//, $data); my $length = 1; foreach $info (@info){ if ( $length < $start]) { substr($mask,($info),1,'N'); $length++; } if (( $length >= $start) && ($length <= $end)) { next; $length++ } if ($length > $end) { $count++; } } $buf .= $data; print OUT "$mask"; close OUT; close MASK; } }