in reply to substitution in $0

You are opening the file in append mode!
Try
open (PROG, "+<$filename");