#! perl -slw
use strict;
sub buk {
my $string = shift;
my @pals;
while( $string =~ m[(.) (?=( (?:\1) | (?:.\1) ) ) ]gx ){
my( $left, $right ) = ( $-[ 0 ], $+[ -1 ] );
while( $left and $right < length( $string )
and substr( $string, $left, 1 ) eq substr( $string, $right, 1
+)
) {
$left--; $right++ ;
}
my $pal = substr( $string, $left, $right - $left );
if( !@pals or length( $pals[ -1 ] ) < length( $pal ) ) {
@pals = $pal;
}
else {
push @pals, $pal unless @pals;
}
}
return wantarray ? $pals[ 0 ] : @pals;
}
print $ARGV[ 0 ];
print ' ' x index( $ARGV[ 0 ], $_ ), $_ for buk $ARGV[ 0 ];
__END__
P:\test>382567 1111111121111111111112111111111111111111111112111111111
+111211111
1111111121111111111112111111111111111111111112111111111111211111
11111121111111111112111111111111111111111112111111111111211111
P:\test>382567 1111111121111111111112111111111111111111111112111111111
+1121111
11111111211111111111121111111111111111111111121111111111121111
111111111111211111111111111111111111211111111111