in reply to separation a string

substr could be your friend: it gets you substrings, starting at a defined offset and with a defined length. Now all you have to do is to create suitable loops for the required offsets and lengths.

HTH, Rata

Replies are listed 'Best First'.
Re^2: separation a string
by Anonymous Monk on Nov 03, 2011 at 10:03 UTC

    yes,substr was the only thing that i used, but my bigger problem is that i don't want to just separate 2-2 or 3-3. i need to have all 2 alphabets or 3 alphabets words as i brought in example. thank you again.

      i need to have all 2 alphabets or 3 alphabets words

      You can call substr() repeatedly in a loop (as Ratazong pointed out), which gives you all 2/3/...-substrings.  I'm not 100% sure what your task is, but judging from the sample output, you seem to want something like this:

      my $s = "AACCCDGYAEELPSWWYAOOLLLSSBBBDDD"; for my $len (2..4) { my @parts; for my $offs (0..length($s)-$len) { push @parts, substr($s, $offs, $len); } print "i=$len: @parts\n"; } __END__ i=2: AA AC CC CC CD DG GY YA AE EE EL LP PS SW WW WY YA AO OO OL LL LL + LS SS SB BB BB BD DD DD i=3: AAC ACC CCC CCD CDG DGY GYA YAE AEE EEL ELP LPS PSW SWW WWY WYA Y +AO AOO OOL OLL LLL LLS LSS SSB SBB BBB BBD BDD DDD i=4: AACC ACCC CCCD CCDG CDGY DGYA GYAE YAEE AEEL EELP ELPS LPSW PSWW +SWWY WWYA WYAO YAOO AOOL OOLL OLLL LLLS LLSS LSSB SSBB SBBB BBBD BBDD + BDDD