use strict; use warnings; my $data = <) { if (my ($number) = m/(\d+)/) { s/\b\p{Alpha}+\b/$number/g; } else { warn "Malformed record in input line $.\n$_\nContinuing.\n"; } print; } #### 0 0 0 0 13 13 13 28 28 28 42 42 42 42 55 55 55 55 55