You could calculate your own timeout time depending on the length of the input after receiving the header like
my $timeout = 120 + int($size/1024)*60;
or something simular. Perhaps you have to play around with the "120" and "60" to get values fitting with your environment.
Other posts pointed out how to set this timeout-time after calculating it.