>perl -wMstrict -le "my %d = ( foo => sub { \"[@_]\"; }, bar => sub { \"(@_)\"; }, ); $_ = 'foo fooz bar'; s/ (\w+) (?(?{ !$d{$1} }) (?!)) / $d{$1}->($1) /xge; print; " [foo] [foo]z (bar) >perl -wMstrict -le "my %d = ( foo => sub { \"[@_]\"; }, bar => sub { \"(@_)\"; }, ); $_ = 'foo fooz bar'; s/ (\w+) / $d{$1}->($1) /xge; print; " Use of uninitialized value in subroutine entry at ... Can't use string ("") as a subroutine ref while "strict refs" ... >perl -wMstrict -le "my %d = ( foo => sub { \"[@_]\"; }, bar => sub { \"(@_)\"; }, ); $_ = 'foo fooz bar'; s/ (\w+) / $d{$1} ? $d{$1}->($1) : $1 /xge; print; " [foo] fooz (bar)