in reply to Extract string after removing the substring

Just in case this may be helpful as a future reference, here are two non-substr ways to get the results you want:

use Modern::Perl; my $string = 'ATATTTATATTAT'; my ( $subStr1, $theRest1 ) = unpack '(a3)(a*)', $string; say $subStr1; say $theRest1, "\n"; my ( $subStr2, $theRest2 ) = $string =~ /(.{3})(.+)/; say $subStr2; say $theRest2;

Output:

ATA TTTATATTAT ATA TTTATATTAT

unpack expands the original string into two chunks: the first being three characters and the second is the rest of the string. The second method uses two captures within a regex, matching three characters and then the remaining characters.

Replies are listed 'Best First'.
Re^2: Extract string after removing the substring
by AnomalousMonk (Archbishop) on Oct 24, 2012 at 20:22 UTC
    ... two non-substr ...

    ... and non-destructive to the original string, as opposed to the 4-argument substr approach.

      Excellent point, AnomalousMonk!