perl -e '$foo = 12345; $foo =~ s/(\d)/func(@+)/ge; sub func { print "@_\n" }' 1 1 2 2 3 3 4 4 5 5