sub space_subst { my $s = shift; $s =~ s/ /_/g; return $s; } s/`(\w+\s+[\w\s]+)`/space_subst($1)/eg;