in reply to Search and replace with expansion

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = '1 2 3*2 4 5x3 6X4'; print qq{before: '$s'}; ;; my %operator = ( '*' => sub { return $_[0] * $_[1]; }, 'x' => sub { return join q{ }, ($_[0]) x $_[1]; }, ); ;; $s =~ s{ (\d+) ([xX*]) (\d+) } { $operator{lc $2}->($1, $3) }xmsge; print qq{after: '$s'}; " before: '1 2 3*2 4 5x3 6X4' after: '1 2 6 4 5 5 5 6 6 6 6'