#!/usr/bin/perl use strict; use warnings; my $data = "123456789"; # get two digits, and replace them with two digits # and a space (globally repeating until the end of # the string) $data =~ s/(\d{2})/$1 /g; print $data, "\n";