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

Hai just try this

$str='url Title: Mary moo-cow 856 invalid url Title: the mechanics 856 valid url Title: Mary moo-cow 858 invalid'; my @string =split/\n/, $str; my @arr=(); for (@string) { if ($_ =~m#url Title:\s((.+?)\s(\d+)) invalid#gsi) { push(@arr,$1); } } print "$_\n" for @arr;

output:

Mary moo-cow 856

Mary moo-cow 858