Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:57:38+00:00 2026-05-22T12:57:38+00:00

I’m having a little trouble comprehending this simple use of the /e regex modifier.

  • 0

I’m having a little trouble comprehending this simple use of the /e regex modifier.

my $var = 'testing';
$_ = 'In this string we are $var the "e" modifier.';

s/(\$\w+)/$1/ee;

print;

Returns: “In this string we are testing the “e” modifier.”

I cannot see why two ‘e’ modifiers are required. As far as I can see, $1 should capture ‘$var’ from the string and a single ‘e’ modifier should then be able to replace the variable with its value. I must be misunderstanding something however, since trying the above code with just one ‘e’ modifier does not visibly replace anything in the string.

Excuse me for asking such a simple question!

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:57:39+00:00Added an answer on May 22, 2026 at 12:57 pm

    It’s not exactly a “simple” question, so don’t beat yourself up.

    The issue is that with a single /e, the RHS is understood to be code whose eval’d result is used for the replacement.

    What is that RHS? It’s $1. If you evaluated $1, you find that contains the string $var. It does not contain the contents of said variable, just $ followed by a v followed by an a followed by an r.

    Therefore you must evaluate it twice, once to turn $1 into $var, then again to turn the previous result of $var into the string "testing". You do that by having the double ee modifier on the s operator.

    You can check this pretty easily by running it with one /e versus with two of them. Here’s a demo a both, plus a third way that uses symbolic dereferencing — which, because it references the package symbol table, works on package variables only.

    use v5.10;
    
    our $str = q(In this string we are $var the "e" modifier.);
    our $var = q(testing);
    
    V1: {
        local $_ = $str; 
        s/(\$\w+)/$1/e;
        say "version 1: ", $_;
    
    }
    
    V2: {
        local $_ = $str;
        s/(\$\w+)/$1/ee;
        say "version 2: ", $_;
    }
    
    V3: {
        no strict "refs";
        local $_ = $str;
        s/\$(\w+)/$$1/e;
        say "version 3: ", $_;
    }
    

    When run, that produces:

    version 1: In this string we are $var the "e" modifier.
    version 2: In this string we are testing the "e" modifier.
    version 3: In this string we are testing the "e" modifier.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.