my $match = 0; my $result; foreach(split /\n/, $content) { if(/Match String/) { $match = 1 } elsif($match && /something/) { $reult = $1; last; } }