in reply to Regex get Text between two strings with colon

G'day MurciaNew,

Here's a technique that will read your data in blocks, by localising a temporary value for the input record separator ($/).

#!/usr/bin/env perl use strict; use warnings; my %data; { local $/ = ":\n"; my $block_re = qr{\A(.*)^(.*?):?\Z}ms; my $key; while (<DATA>) { my ($data, $label) = /$block_re/; $data{$key} = $data if defined $key; $data{$key} .= $label if eof DATA; $key = $label; } } use Data::Dump; dd \%data; __DATA__ AAA: 123 456 789 BBB: qwe rty uio CCC: asd fgh jkl

Notes:

Here's the output from that code:

{ AAA => "123\n456\n789\n", BBB => "qwe\nrty\nuio\n", CCC => "asd\nfgh\njkl\n", }

— Ken