my $match = 0; my $result = undef; foreach(split /\n/, $content) { if(/End Date/) { $match = 1 } elsif($match && /(\d\d \w\w\w \d\d\d\d)/) { $result = $1; last; } }