in reply to want regex to find 2nd and 3rd occurence of a character

I agree with moritz in that you might want to use another approach now that you have your string split into an array.

This sounds like it might be a job for List::MoreUtils:

use strict; use warnings; use List::MoreUtils qw(natatime); my $str="AJKDHAKAESRADADKLASRRASDASDKASEKA"; my @ar = split '(?<=[KR](?!P))', $str; #to split where i ever i see a +K or R. print "ar: @ar\n"; my @new; my $it = natatime 2, @ar; while (my @vals = $it->()) { push @new, (join '', @vals); } print "new: @new\n";

prints:

ar: AJK DHAK AESR ADADK LASR R ASDASDK ASEK A new: AJKDHAK AESRADADK LASRR ASDASDKASEK A

Is that what you are looking for for question #1? If so, I think you can use the natatime function to also solve #2.

Update: OP has been updated.
Also, it is best if you just put code snippets inside <code> tags, rather than the bulk of your question.

Replies are listed 'Best First'.
Re^2: want regex to find 2nd and 3rd occurence of a character
by heidi (Sexton) on May 22, 2008 at 19:34 UTC
    hi toolic... THATS BRILLIANT....thank you so much... its working perfect... Amazing .... cool module. i will start using it efficiently !!! Perl monks rocks :) Thanks :)