http://qs1969.pair.com?node_id=1202332


in reply to Extract and print two specific keys and values using %

Here is one way to get the output you specify:
use warnings; use strict; while (<DATA>) { if (/(id "\w+";).+(name "\w+";)/) { print "$1 $2\n"; } } __DATA__ A B C . id "ABS0056"; D; E; F; G; name "SAM"; H; I; J; K; A B C . id "ABS0059"; D; E; F; name "JOE"; G; H; I; J; K; A B C . id "ABS0060"; D; E; F; G; name "MARY"; H; I; J; K; A B C . id "ABS0057"; D; E; F; G; H; name "BILL"; I; J; K; A B C . id "ABS0065"; D; E; name "RONIE"; F; G; H; I; J; K; A B C . id "ABS0061"; D; E; F; G; name "STEPHAN"; H; I; J; K;

I made a change to your input data: I changed the funky quotes to simple quotes. Read perlre to understand the capturing parentheses and $1 nd $2.