use LWP::Simple; foreach $ID (@ID) { $content=" "; $url="http:://...docid=$ID"; # this is completely NEW value $content=get($url); # here you APPEND new value to the previous values open FILE, ">> C:/perl/output.txt"; print FILE $content; }