use Modern::Perl; my $v2 = <. EOL for my $filepath ( @ARGV ) { my $fh; open( $fh, '<', $filepath) or die "Cannot open $filepath"; my @lines = <$fh>; close $fh; my $file_content = join '', @lines; $file_content =~ s/\Q$v2\E/$v3/ims; open( $fh, '>', $filepath); print $fh $file_content; close $fh; }