my $sentence = 'The quick brown fox jumped over the lazy dog'; my $substring = 'quick.*?fox'; $sentence =~ s{$substring}{big bad wolf}; #### my $sentence = 'The quick brown fox jumped over the lazy dog'; my $substring = 'The.*?fox'; $sentence =~ s{$substring}{big bad wolf};