note robin Taking your clever precheck a stage further gives a 50%-ish speed improvement on my iBook:<br> (<b>Update</b>: On a faster Linux PC the improvement is much less pronounced: only about 8–10%.) <code> use List::Util qw( min max ); sub fannkuch { my ( \$aref, \$level ) = ( @_, 0 ); my ( \$index, \$copy, \$ok ) = ( \$level, [@\$aref], \$level + 1 == @\$aref ); do { if (\$ok) { if (max(@\$copy[0..(\$copy-> - 1)]) != \$copy-> && min(@\$copy[(\$copy->[-1] - 1)..\$#\$copy]) != \$copy->[-1]) { my @q = @\$copy; my ( \$k, \$flips ); for ( \$flips = 0 ; ( \$k = \$q ) != 1 ; \$flips++ ) { @q[ 0 .. \$k-1 ] = reverse @q[ 0 .. \$k-1 ]; } if ( \$flips > \$maxflips ) { \$maxflips = \$flips; @max_sequence = (); } push @max_sequence, join '', @\$copy, "\n" if ( \$maxflips == \$flips ); } } else { fannkuch( \$copy, 1 + \$level ); } @\$copy[ \$index - 1, \$index ] = @\$copy[ \$index, \$index - 1 ] if \$index != 0; } while \$index-- > 0; return \$maxflips; } </code> Incidentally, I tried changing the code to use Algorithm::FastPermute (which implements the same permutation algorithm in C) and the runtime actually increased. I don't know why that's happening. <strike>It may be an unfortunate side-effect of the stability improvements in my latest version of A::FP, or it may be something else entirely.</strike> <i>Update</i>: no, it's nothing to do with the recent changes. I get the same result using an old version too. 513179 513179