$foo =~ s/(tim)(\d{5})(struppi)/$1 . tuwas($2) . $3/e; sub tuwas {}