my $sentence = 'Sam goes to school to play football.'; # Count the spaces and add 1 my $count1 = substr($sentence, 0, 12) =~ y/ // + 1;