my $t='the quick red fox jumped over the lazy brown dog'; print count_vowels($t); sub count_vowels { my $string = shift; # Check degenerate case: a single character string. if (length($string) == 1) { return 1 if $string =~ /a|e|i|o|u/i; return 0; } # Break the problem into two smaller problems: my ($part1, $part2) = (substr($string,0,1), substr($string,1) ); return count_vowels($part1) + count_vowels($part2); }