sub ccn {
local $_ = shift;
my @n;
for (my $i = 0; $i < length; pos = $i++) {
$n[length $&] = $& if /\G(.+).?(??{reverse $1})/;
}
return @n ? $n[-1] : '';
}
sub ccn2 {
local ($_, $s) = shift;
for (my $i = 0; $i < length; pos = $i++) {
$s = $& if /\G(.+).?(??{reverse $1})/ and length($s) < length
+($&);
}
return $s;
}
|
Update: minor bugs fixed
Update2: improved version added