$ 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