#!/usr/bin/perl use warnings; use strict; my $wordcount = 0; my $linenumber = 0; my $wordnumber = 0; my $findword = "and"; open(FILE, "< input.txt") or die "Cannot open file: $!"; my @lines = ; close(FILE) or die "Cannot close file: $!"; foreach my $line (@lines) { $linenumber++; my @words = split(/\s+/, $line); foreach my $word (@words) { $wordnumber++; if ($word =~ m/^and$/) { print qq(The word "$findword" occured in line $linenumber at word $wordnumber\n); } } $wordnumber = 0; }