#! perl -slw use strict; sub z { my $soFar = 1; my $lastC = substr $_[0], 0, 1; my( $lastP, $bestN, $bestP ) = ( 0 ) x 3; for my $p ( 1 .. length( $_[0] )-1 ) { my $this = substr $_[0], $p, 1; my $d = abs( $this - $lastC ); if( $d != 1 and $d != 9 ) { $soFar = 1; $lastP = $p; } ++$soFar; if( $soFar > $bestN ) { $bestN = $soFar, $bestP = $lastP; } $lastC = $this; } return $bestN, $bestP; } while( ) { chomp; print; my( $l, $p ) = z( $_ ); print ' ' x $p, substr( $_, $p, $l ), "\t", $l, "\n"; } __DATA__ 01234567890123456789 78901234567890123456 98765432109876543210 21098765432109876543 01234567890987654321 012345678890123456789 789012345677890123456 987654321099876543210 210987654322109876543 012345678900987654321 012345678909876543210