in reply to capturing from Input file

As long as your input file is not too large you could slurp the whole file into one string and do global matches against it. Use the s flag in the regex to allow the dot metacharacter to match newlines.

use strict; use warnings; open my $inputFH, q{<}, \ <<'END_OF_FILE' or die qq{open: $!\n}; end sleep 10 dis qremote(MQSI.3PL846)RNAMERQMNAME1 : dis qremote(MQSI.3PL846) RNAME + RQMNAME AMQ8409: Display Queue details.QUEUE(MQSI.3PL846)TYPE(QREMOTE)RQMNAME( +MSTBKRQ1)RNAME(MQSI.3PL846) end2 : end Starting MQSC for queue manager NTTCSWQ1. AMQ8409: Display Queue details.QUEUE(MQSI.3PL944)TYPE(QREMOTE)RQMNAME( +MSTBKRQ1)RNAME(MQSI.3PL944) exit 5724-H72 (C) Copyright IBM Corp. 1994, 2004. ALL RIGHTS RESERVED. 1 : dis qremote(MQSI.ADM850) RNAME RQMNAME AMQ8409: Display Queue details. QUEUE(MQSI.ADM850) TYPE(QREMOTE) RQMNAME(MSTBKRQ1) RNAME(MQSI.ADM850) 2 : end end sleep 10 exit AMQ8409: Display Queue details. QUEUE(MQSI.ADMAPTR) TYPE(QREMOTE) RQMNAME(MSTBKRQ1) RNAME(MQSI.ADMAPTR) 2 : end One MQSC command read. No commands have a syntax error. All valid MQSC commands were processed. END_OF_FILE my $lines = do { local $/; <$inputFH>; }; close $inputFH or die qq{close: $!\n}; my $rxExtract = qr {(?xs) AMQ8409 .*? QUEUE\(([^)]+)\) .*? RQMNAME\(([^)]+)\) .*? RNAME\(([^)]+)\) }; while ( $lines =~ m{$rxExtract}g ) { print qq{QUEUE: $1, RQMNAME: $2, RNAME: $3\n}; }

The output.

QUEUE: MQSI.3PL846, RQMNAME: MSTBKRQ1, RNAME: MQSI.3PL846 QUEUE: MQSI.3PL944, RQMNAME: MSTBKRQ1, RNAME: MQSI.3PL944 QUEUE: MQSI.ADM850, RQMNAME: MSTBKRQ1, RNAME: MQSI.ADM850 QUEUE: MQSI.ADMAPTR, RQMNAME: MSTBKRQ1, RNAME: MQSI.ADMAPTR

I hope this is helpful.

Cheers,

JohnGG