system("sed -e 's/$search/$replace/g' $File1 > $Replace_html"); #### open (my $fh, "-|", 'sed', '-e', "s/$search/$replace/g", $File1); my $new_file = do { local $/; <$fh> }; # grab sed's output # now you can write the contents of $new_file to a file yourself.