My toughts, too. Regex's seem like an overly complicated solution to me; but, on the other hand, it's a good problem to learn some pretty empowering Regex strategies. So "Your mileage may vary."

Here is a quick sript that uses substr() and index() to find the search-for pattern and deletes everything up to the pattern plus that pattern. It also only searches up to the specified number of characters.

#!/usr/bin/perl use strict; use warnings; my @strings = ('ATGGCTAGTTTCAGT', 'GTTTATGGGTACGTGT', 'ATTGATACGGGTATTTAGGCTG', 'ATTAGGAAGTAGGACCCTAGG' ); my $search = 'TTT'; my $len = length($search); my @newStrings = map {my $indx = index(substr($_,0,8),$search); my $temp; if($indx == -1){ $temp = $_; }else{ $temp = substr($_, ($indx+$len),(length($_)-$in +dx-$len)); } } @strings; foreach my $indx1 (0..(scalar(@strings)-1)){ print "$strings[$indx1] ---> $newStrings[$indx1]\n"; } exit(0);

This script produces the following output:

ATGGCTAGTTTCAGT ---> ATGGCTAGTTTCAGT GTTTATGGGTACGTGT ---> ATGGGTACGTGT ATTGATACGGGTATTTAGGCTG ---> ATTGATACGGGTATTTAGGCTG ATTAGGAAGTAGGACCCTAGG ---> ATTAGGAAGTAGGACCCTAGG

If I understand the OP's inquiry, I think this does what is wanted.

The only thing I'm not clear on is what the OP expects to do if there are (1) multiple occurances, within the seek-or number of characters, of the search-for pattern in the string? and (2) what the result should be if there is a run of the search-for pattern (e.g., 'TTTTTTTTT' which has three intances of the search-for pattern in a run)?

ack Albuquerque, NM

In reply to Re^2: how to search for a pattern in a string within a certain range by ack
in thread how to search for a pattern in a string within a certain range by BhariD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.