perl -MO=Deparse -M"5;$S=shift;$R=shift;open $o,'>','new2.txt'" -ne "chomp;if($_=~/$S/){print qq/$_ $R?/;($_=$_)=~s/$S/$R/ if=~/y/}print$o $_.$/" sub BEGIN { require 5; () } $S = shift @ARGV; $R = shift @ARGV; open $o, '>', 'new2.txt'; LINE: while (defined($_ = readline ARGV)) { chomp $_; if ($_ =~ /$S/) { print "$_ $R?"; ($_ = $_) =~ s/$S/$R/ if readline(STDIN) =~ /y/; } print $o $_ . $/; } -e syntax OK