On Jul 3, George P. said: >> while ($string =~ /pattern/g){ >> $count++; >> if ($count > $max_count){ >> $string = substr($string,0,pos($string)); >> last; >> } >> } > >$string =~ s/((.*?$pattern){$max_count})(.*)/$1/s;
You don't need to capture the .* at the end of the regex. This is one of those cases where I my \K anchor/assertion idea would really come in handy: s/(?:.*?$pattern){$max_count}\K.*//s; What the \K does is make the regex think it JUST started matching, so instead of replacing a bunch of stuff plus some extra fluff with the original bunch of stuff, we just say "after you've matched X, pretend you started matching HERE." It comes in handy in substitutions that look like s/(A)B/$1/; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]