in reply to Search and replace

    $line =~ s/input .*clk/output .*clk/g;

The first part of s/// is a regular expression but the second part is a string. It is essentially s/REGEX/STRING/. Since (in the first part of your task, which is the only part your code attempts to address) there are no complications, you can ignore the rest of the pattern and just do this:

$line =~ s/input/output/;

That should get you farther along. For the general case you would need to use capture groups.


🦛

Replies are listed 'Best First'.
Re^2: Search and replace
by kulua (Initiate) on May 23, 2021 at 15:39 UTC

    Hi Hippo ,

    I want to change the string to output when the string clk matches not the input to output

    Can you provide me good tutorial for reg expression ?

      $line =~ s/input(?= .*clk)/output/g;

      Untested since no test cases were provided.