while(){ next unless /^(?:A|The) (.*) is found$/; my $item = $1; my $next_line = ; next unless $next_line =~ /^at location (.*)/; my $location = $1; # needs chomp'ing?? printf "'%s' is as [%s]\n", $item, $location; # or shove into some data structure }