Try the global match (g) and eval (e) flags. Here's an example:
#!/usr/local/bin/perl while (<>) { s/([A-Z]+)/reverse($1)/ge; print; }
The first part is obvious: It matches 1 or more capital characters in the range A-Z, and grabs it to $1. The 'e' flag on the regexp causes the the 'reverse($1)' to be eval'd and the return value to be substituted in, and the 'g' flag makes as many matches as possible. This particular example reverses any and all sections of capital letters so "LREP java PYTHON" would become "PERL java NOHTYP".

Instead of using the reverse function, write your own function to do the database access, pass it the matched data and have it return what should be substituted in.

Just a warning: I haven't run any benchmarks or anything, but this will probably cause a pretty big speed hit since you are running an eval() on every match.

Update:
Here are my untested changes to your code. It may or may not work.

sub getfromdb { $diagId = shift; $dbh = ConnectDB($User, $Password); $sql = "SELECT version FROM diagramversion WHERE diagram_id='$ +diagId' AND workflow_state='Stored'"; #to_char(version,'099') didn't + work $sth = RunJobDB($dbh, $sql); @version = $sth->fetchrow_array; $version = $version[0]; $sth->finish(); DisconnectDB($dbh); $version = sprintf( "%03d", $version ); $fullId = $diagId."-".$version; return("dia_View.pl+?diagram_id=$fullId"); } $$imageMap =~ s/ViewObject.pl\?name=(.*?)_DIAGLINK/getfromdb($1)/gei;

Yet Another Update:
Variable names like '$$imageMap' are very difficult to maintain and it's almost impossible to make sure you don't walk all over important variables. Try using a hash instead.

--
IndyZ


In reply to Re: multiple substitutions by IndyZ
in thread multiple substitutions by Loose Moose

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.