http://www.perlmonks.org?node_id=494762


in reply to Ternary inside a regex

At worst, another way with the ternary (or "conditional") operator:
use vars qw ( $message); $message = qq ( Foo bar <font size="7"> phrase here </font> blivits. ) +; $message =~ s#(\d+)#($1 > 5) ? 5 : $1#eisg; if ( $1 ) { print "\n After s###, \$1 is: $1 \n ...and revised \$msg is: +$message \n"; } else { print "\n no \$1 found \n"; }
and output is:
After s###, $1 is: 7
...and revised $message is: Foo bar <font size="5"> phrase here </font> blivits.