use strict; use warnings; my $f1 = '1.txt'; my $f2 = '2.txt'; my (@strings, $text); open (FH, $f1) || die; chomp(@strings = <FH>); open (FH, $f2) || die; $text = join '', <FH>; $text =~ s/\Q$_\E/******/g for @strings; ### Make sure it's treated as string and not expression open (FH, ">$f2") || die; print FH $text; close FH;
1.txt:
find search
2.txt:
a bunch of words with find and search and some other words
2.txt after run:
a bunch of words with ****** and ****** and some other words
In reply to Re: Read strings from a file, search and replace same string in another file.
by TJPride
in thread Read strings from a file, search and replace same string in another file.
by premal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |