in reply to new line every match
Rather than split'ing the line on spaces use a look-ahead to do it at a point followed by the text "address".
knoppix@Microknoppix:~$ perl -E ' > $line = qq{address 6433 main st address 6434 main st address 6435 ma +in st\n}; > chomp $line; > say for split m{(?=address)}, $line;' address 6433 main st address 6434 main st address 6435 main st knoppix@Microknoppix:~$
I hope this is helpful.
Update: A more complete solution catering for the two header lines and split'ing at a space that is followed by the text "address".
knoppix@Microknoppix:~$ perl -Mstrict -Mwarnings -E ' > open my $inFH, q{<}, \ <<EOF or die $!; > This is the list of address > here are the addreses > address 6433 main st address 6434 main st address 6435 main st > EOF > > print scalar <$inFH> for 1 .. 2; > my $line = <$inFH>; > chomp $line; > say for split m{\s+(?=address)}, $line;' This is the list of address here are the addreses address 6433 main st address 6434 main st address 6435 main st knoppix@Microknoppix:~$
Cheers,
JohnGG
|
|---|