in reply to Writing to a file

$ cat file.txt old/path/to/some/file another/old/path/to/some/file one/more/old/path/to/some/file $ perl -pe 's#\bold(?=/path/to/some/)#new#g' file.txt new/path/to/some/file another/new/path/to/some/file one/more/new/path/to/some/file
But I don't think that's what you meant. That means your sample input & output isn't representative enough of the actual problem.

Replies are listed 'Best First'.
Re^2: Writing to a file
by victorz22 (Sexton) on May 05, 2017 at 20:37 UTC

    well that sample i gave isn't my actual data but i do need a block of paths to be replaced, also I need a solution that works in a program and not a command line call. Thanks anyways though.

      Just for future reference, a "command line call" can usually be converted into a "program" fairly easily:

      c:\@Work\Perl\monks>perl -MO=Deparse -pe "s#\bold(?=/path/to/some/)#ne +w#g" LINE: while (defined($_ = <ARGV>)) { s[\bold(?=/path/to/some/)][new]g; } continue { die "-p destination: $!\n" unless print $_; } -e syntax OK
      See O and B::Deparse.


      Give a man a fish:  <%-{-{-{-<

      Translating such a Perl one-liner into an actual program is fairly simple, and we can help you. But the real point is this: is this what you need?

        No the directories do not differ by one word some are entirely different