Contents of pp.txt is as below. asabast@xyz.com pxpx@xyz.com jxbx@xyz.com And the out put i want is asasbast\@xyz.com pxpx\@xyz.com jxbx\@xyz.com $file = "pp.txt" ; open (FH ,$file) || die ("could not openfile"); while () { $_ =~ s/\s+$//; s/\@/\\@/; s/.com/.com /; $line = $_; print $line; } close (FH);