if ($found_goal) { my $i = $goal; while (-1 != $i) { print $word_string[$i], "\n"; $i = $previous[$i]; } } else { print "no word ladder.\n"; }