#!/usr/bin/perl use warnings; use strict; my $sentence = "Sam goes to school to play football"; my $word = substr($sentence,12,17-12+1); my $next_word = substr($sentence,27,34-27+1); my $find_word = word_counter($sentence); print "$word: ", $find_word->($word),"\n"; print "$next_word: ", $find_word->($next_word),"\n"; sub word_counter { my $sentence = shift; my @words = split " ",$sentence; return sub { my $word = shift; my $count = 0; for (@words) { $count++; return $count if ( $word eq $_ ); } return 0; } } #### C:\Code>perl stuff1.pl school: 4 football: 7