in reply to variation on splitting a string into elements of an array
in thread splitting a sequence using unpack

X will back up a byte. So:
my $line ='atgcatccctttaat'; my @trips = unpack('a3X2' x (length($line)-2), $line); print join "\n", @trips;
yields:
atg tgc gca cat atc tcc ccc cct ctt ttt tta taa aat

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: variation on splitting a string into elements of an array
by Roy Johnson (Monsignor) on Mar 02, 2005 at 19:00 UTC
    This uses the same technique to extract three frame sequences into separate arrays:
    my $line ='atgcatccctttaat'; my @trips; my $frame; for (unpack('a3X2' x (length($line)-2), $line)) { push @{$trips[$frame++]}, $_; $frame %= 3; } use Data::Dumper; print Dumper \@trips;
    output:
    $VAR1 = [ [ 'atg', 'cat', 'ccc', 'ttt', 'aat' ], [ 'tgc', 'atc', 'cct', 'tta' ], [ 'gca', 'tcc', 'ctt', 'taa' ] ];

    Caution: Contents may have been coded under pressure.