sub check_string($word) { foreach $chr (split //, $word) { $check .= $chr; if whole_word($check) { push @phrase, $check; $rem = substr($word, length($check), length($word) - length($check)); check_string($remainder); } elsif not_valid($check) { @phrase = (); return; } } print "@phrase\n"; @phrase = (); }