^(\d\s)?(\d{2}\s)+/(\d\s)?(\d{2}\s)+
s#([\d ]+) / ([\d ]+##g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
my @a = ( '0 11 11 / 11 11', '0 11 11 / 111 111', '0123 / 111 11 11', '011 / 1 111 1111', '012 3 / 11 11 1 ', ); sub formatieren { my $num = shift; $num =~ s/\s//g; $num = reverse join(' ', unpack('(A2)*', reverse $num)); return $num; } for my $tel (@a) { $tel =~ s#^([\d ]+)/([\d ]+)$#formatieren($1).' / '.formatieren($2)#e; say $tel; }