in reply to Regex with Newline

Thank you very much! Now it works with the following code:
use strict; use warnings; while(<DATA>) { chomp; $_=~s/(\d{5} \w+)/ \1\n/g; print; } __DATA__ Some Company; Some Street 52 12345 City1 Another Company; Another Street 63 23456 City2 Yet Another Company; New Street 11 34546 City3
Is this a reasonable code or I just have luck now?
Many thanks!
VE

Replies are listed 'Best First'.
Re^2: Regex with Newline
by Marshall (Canon) on Aug 26, 2011 at 15:51 UTC
    I think that is a bit "too clever".

    I was surprised but, this \1 idea did work although it generates a warning message.

    I would argue that easy to understand code is better. And it often executes faster!

    #!/usr/bin/perl -w use strict; my $previous_line; while (<DATA>) { if (/;/) { chomp; $previous_line = $_; } else { print "$previous_line; $_"; } } __DATA__ Some Company; Some Street 52 12345 City1 Another Company; Another Street 63 23456 City2 Yet Another Company; New Street 11 34546 City3