#!/usr/bin/perl
use strict;
my $line;
my $where;
my $key;
my $start;
my $count;
$line="hello how are you\n";
my $length_of_line;
$length_of_line=length($line);
print "the length is $length_of_line\n";
$line="the cat in the thethe hat went to the store the";
my $substring;
$substring="the";
$key="the";
$where=index($line,$substring);
print "I found $substring at position $where in $line\n";
$where=index($line,$substring,4);
print "I found $substring at position $where in $line\n";
# count the umber of instances of a word
do
{
$where=index($line,$key,$start);
if ($where!=-1)
{
$count++;
$start=$where+length($key);
}
} while ($where !=-1);
print "I found the $count times\n";