in reply to Re: separation a string
in thread separation a string

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.

Replies are listed 'Best First'.
Re^3: separation a string
by Eliya (Vicar) on Nov 03, 2011 at 10:31 UTC
    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