#!/usr/bin/perl use strict; use warnings; my $str1 = 'through a file'; my $str2 = 'string'; my $lastStr2Line; 1 while !~ m/$str1/; m/$str2/ and $lastStr2Line = $. while $_ = ; die "String 2 '$str2' not found\n" if ! defined $lastStr2Line; print "String 2 last found on line $lastStr2Line\n"; __DATA__ Here's a good one. Looking to read through a file and then detect a certain string. Then check again sometime later to detect a different string and alert if that different string isn't found. While this string could appear anywhere in the file, I would only want the last found string to run this check on... example: