use strict; use warnings; my $str = "1 2 345 23"; $str =~ s/(\d+)/add($1)/ge; print $str; sub add { my ($num) = @_; return $num + 10; }