use strict; use warnings; my ($start, $keyword, $end) = ('PROC SQL', 'DELQ_STATUS', 'QUIT'); my @block; while () { if (/$start/i .. /$end/i) { push @block, $_; } if (/$end/i) { for (@block) { if (/AS \s+ $keyword/ix) { print join('', @block); last; } } @block = (); } } __DATA__ ... #### 16:19 >perl 1275_SoPW.pl 481 proc sql; 482 create table work.INPUT_ACCT_POOL_3 as 483 select 484 Acct_Key, 485 Arrears_Bal_Amt, 486 ARREARS_DAYS, 531 end) as DELQ_STATUS length = 8 532 format = 8. 533 informat = 8. 534 label = 'DELQ_STATUS', 535 Arrears_Start_Date, 536 PERIODENDING, 537 PRODUCT_TYPE_CODE 538 from &SYSLAST SYMBOLGEN: Macro variable SYSLAST resolves to WORK.INPUT_ACCT_POOL_2 539 ; NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will result in a missing value for the CASE expression. NOTE: Compressing data set WORK.INPUT_ACCT_POOL_3 decreased size by 35.05 percent. Compressed is 9043 pages; un-compressed would require 13923 pages. NOTE: Table WORK.INPUT_ACCT_POOL_3 created, with 5986698 rows and 17 columns. 540 quit; 16:19 >