in reply to matching strings into array from txtfile and printing on same line

Here's another option with your data in the file data.txt:

use Modern::Perl; use File::Slurp qw/read_file/; my $lines; for (read_file 'data.txt') { if ( /Orderbook/ .. /ISIN/ ) { $lines .= $_; } elsif ($lines) { my ( $id, $sy, $is ) = $lines =~ /ID:(.*)[\s\S]+Symbol:(.*)[\s\S]+ISIN:(.*)/; my $line = "$id:$sy:$is"; $line =~ s/\s//g; say $line; $lines = ''; } }

Output:

QYQ:LUP2L100OHM:SE0004017929 R1M:TLS2K50OHM:SE0004018539 QNF:MINILONGOMXAO:SE0003990183 QX8:ALF2K160OHM:SE0004017440 NC0:BOL2K170OHM:SE0003842137 NEV:NOK2K90OHM:SE0003843069