in reply to Conditional regex

Although nowadays I'd prefer to use HTML::Parser or something similar, I think you could use a subroutine call in the replacement part (and use the /e modifier).

sub foo { my $bar = shift; if ( $CONDITION ) { #modify $bar if you need to } return $bar; } my $text =~ s{(<img.+?>)}{foo($1)}sige;

update1: changed quantifier to +?