I am reading a file like this
1
one
2
two
3
three
three
three
four
five
5
In this I want check the sequence one two three four five and print how many times three is present.
My code:
use warnings;
use strict;
open(tempp1,"<$temp1") or die "Could not open file $temp1: $!";
my $count = 0;
while(my $line=<tempp1>) {
if ($line eq "one") {
while(my $line=<tempp1>) {
if ($line eq "two") {
while(my $line=<tempp1>) {
if ($line eq "three") {
$count++;
while(my $line=<tempp1>) {
if ($line eq "four") {
while(my $line=<tempp1>) {
if ($line eq "five") {
last;
}}}}}}}}}}
print "$count\n";
close tempp1;
Output is printing :1 How to correct this?