I Have two files name test1 and test2. The contents of the files are as follows.

test1

```
nijin:qwe123
nijintest:qwerty
nijintest2:abcsdef
nijin2:qwehj

```

test2

```
nijin:qwe
nijintest2:abc

```

I have to change the values of `nijin` and `nijintest2` in test1 to match that in test2, leaving all other values alone. I have tried all possible Perl replace comments without any success. Any help will be appreciated.

**Edit**

I have tried many open close file functions to replace the entry but none of them gives a required output. I have tried everything here [`In Perl, how do I change, delete, or insert a line in a file, or append to the beginning of a file?`](https://stackoverflow.com/questions/4388304/in-perl-how-do-i-change-delete-or-insert-a-line-in-a-file-or-append-to-the-b) . But with no luck