in reply to match word on line - match word on another line - print lines

use strict; my $title; while ( <DATA> ) { $title = $_ if /^Title: .+$/; print $title, $_ if /^856 invalid/; } close IN; __DATA__ Title: Mary moo-cow 856 invalid url Title: the mechanics 856 valid url Title: Terminator 2 856 invalid url