$outfile is the filename. You need to use the file handle $out.
poj
In reply to Re^3: How to modify a file by poj in thread How to modify a file by biancoari