perldoc -q substring
perldoc -f pos
perldoc -f index

update: example

use strict; use warnings; my $YBL027W = 'GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAU +AUGUUAUGA'; my $seq = shift || 'GUAUG'; my @pos; while( $YBL027W =~ m/\Q$seq\E/gis ){ push @pos, pos($YBL027W) - length( $seq ); } print regex => $/; printf ' \%d0', $_ for 1 .. 8; print $/, ( 0 .. 9 ) x 8, $/; print $YBL027W,$/; my $req = ' ' x length $YBL027W; substr($req, $_, 1, '^') for @pos; print $req, $/; print "@pos $/"; @pos = (); for( my $lindex = index( $YBL027W, $seq); $lindex != -1; $lindex = index( $YBL027W, $seq, $lindex + length $seq) # + length $seq so it matches the m//atch solution # otherwise UUU in UUUU would match twice ( [UUU]U and U[UUU] +) ) { push @pos, $lindex; } print $/, index => $/; printf ' \%d0', $_ for 1 .. 8; print $/, ( 0 .. 9 ) x 8, $/; print $YBL027W,$/; $req = ' ' x length $YBL027W; substr($req, $_, 1, '^') for @pos; print $req, $/; print "@pos $/"; __END__ loose$ perl substring.pl regex \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ 0 index \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ 0 loose$ perl substring.pl UUUAA regex \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ ^ 5 48 index \10 \20 \30 \40 \50 \60 \70 + \80 0123456789012345678901234567890123456789012345678901234567890123456789 +0123456789 GUAUGUUUAACAGUGAUACUAAAUUUUGAACCUUUCACAAGAUUUAUCUUUAAAUAUGUUAUGA ^ ^ 5 48 loose$

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.


In reply to Re: look for substrings and getting their location by PodMaster
in thread look for substrings and getting their location by wolffm

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.