package Tie::ScalarIter; sub TIESCALAR { my ($class, $init, $start) = @_; bless [ $init, $start, length($init) ], $class; } sub FETCH { my $s = shift; my $ret = $s->[0]; my $p = $s->[2] - 1; while (1) { substr($s->[0], $p, 1) =~ tr/acgnt/cgnta/; last if substr($s->[0], $p--, 1) ne $s->[1]; $s->[0] = "$s->[1]$s->[0]", $s->[2]++, last if $p < 0; } return $ret; } sub STORE { my $s = shift; my $rep = shift; if (ref $rep) { @$s = (@$rep, length $rep->[0]) } else { (@$s[0,2] = ($rep, length $rep) } } 1;