http://qs321.pair.com?node_id=1120547


in reply to Fix whitespace around symbols

What code have you already written?

Personally, I would extract the "special" symbols and their surrounding whitespace from the first sentence and then replace the elements accordingly in the second sentence:

my %symbols = ( '/' => [], '*' => [], '-' => [], ); $_= "This is a perl script/program."; push @{ $symbols{ '/' }}, m!(\s*[/]\s*)!; push @{ $symbols{ '*' }}, m!(\s*[*]\s*)!; push @{ $symbols{ '-' }}, m!(\s*[-]\s*)!; my $target= "C'est un perl script / programme"; $target =~ s!\s*([/*-])\s*!shift $symbols{ $1 }!ge;