my @filelines = ; #Read the entire file into an array my $whichline; #Declare a variable to hold the line number for(my $i = 0; $i = $#filelines; $i++){ #Go through the entire array untill you find it or run out of lines if($filelines[$i] =~ m/TEXTTOMATCH/o){ #Attempt to match, use compile-once $whichline = $i; #If match, remember the line and leave the loop. last; } }