Input:
--- START ---
abc
def
string1
das
dsfa
string2
dasf
string1
string2
dfsdsf
--- END ---

Code:
--- START ---
#!/usr/bin/perl

use warnings;
use strict;

die "Wrong usage\n" unless (defined $ARGV[0] and -f $ARGV[0]);
open my $FH, "< $ARGV[0]" or die "Can't open file\n";

my $string1 = 0; # Track if the first string occurred last line
while (<$FH>) {
    print "$_"; # Echo the line
    if ($string1) { # We hit string1 last line...
        if (/string2/) { # ...and string2 this line
            print "Found the double string!\n";
        }
    }
    $string1 = (/string1/);
}
close $FH;
--- END ---

Output:
--- START ---
abc
def
string1
das
dsfa
string2
dasf
string1
string2
Found the double string!
dfsdsf
--- END ---


HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to