while(<>){chomp;$h=length; for($i=$c="";$i<$h;$i++){ for($j=$i;$j-$i<9;$j++){ $a=substr$_,$i,$j-$i+1; $b=join"",sort{$b-$a}split//,$a; $a ne$b or length$c<length$a and$c=$a}} print"$c\n"}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).