my @matches; open (F,"files.txt") || die ("Couldn't open file: $!\n"); while() { chomp; if (/matchingstffHere/) { push(@matches, $_); } } close(F); if (scalar(@matches) >= 3) { print "Needed = $matches[2].\n"; }