You can split on the full-stops (which are regular expression metacharacters so need to be escaped) but use capturing parentheses in the regex so that they are retained in the resulting array; (have a look at perlretut, perlreref and perlre). Then you can construct your new string by interpolating array slices (Slices) in a double-quoted string, first having set the list separator (see $LIST_SEPARATOR in perlvar) to an empty string so that each element abuts the next.
$ perl -E ' > $text = q{this.is.example.text}; > @items = split m{(\.)}, $text; > say for @items; > $new = do > { > local $" = q{}; > qq{[@items[ 0 .. 3 ]] [@items[ 4 .. 6 ]]}; > }; > say $new;' this . is . example . text [this.is.] [example.text] $
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Merging in perl
by johngg
in thread Merging in perl
by cthar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |