If your string result is so huge that the copy really is a problem, you can temporarily make an alias like this:
for my $seq ($_[0]->seq()) {
# in case you need to reset the first match position
# (avoid pos() on huge strings)
# $seq =~ /\za/g;
$CG++ while $seq =~ /CG/g;
}
update
Interesting enough, due to the way the perl internals work, this doesn't save you memory compared to
my $seq = $_[0]->seq();
during the processing, but the gain is less wasted memory
when $seq goes out of scope again (this isn't a memory leak,
perl will reuse that memory if the scope is entered again) |