my ($x,$y,$redline); while () { if ($redline) { ($x,$y) = /at location (\S+) (\S+)/; print "$x $y\n"; } $redline = /red line/; }