#!/usr/bin/perl -w
use strict;
use Data::Dumper;
local $/ = '';
my $data = <DATA>;
do {
$data =~ m|(<Text>.+</Text>)|s;
my $prepared_string = prepare_string($1);
$data =~ s/$1/$prepared_string/s;
} while($1);
print Dumper $data;
## subs ##
sub prepare_string {
my $string = shift;
$string =~ s/\n|<Text>|<\/Text>//g;
my $chunk_size = 4;
my $prepared_string;
for (my $i = 0; $i <= length($string); $i=$i+4) {
my $part = substr($string, $i, $chunk_size);
$prepared_string .= "<Text>$part</Text>\n";
}
return $prepared_string;
}
__DATA__
<Feld><Text>Hallo liebe Perl-Gemeinde,
ich wünsche euch ein schönes Fest und
einen guten Rustch ins neue
Jahr.</Text></Feld><Sig>
abc</Sig>