# read through big string with changed end-of-line :) # untested my @bigHTML; do { local $/ = ''; # or "\n" maybe open my $fh, '<', \$html[$i] or die "..."; my $smallstring = ''; while(<$fh>) { $smallstring .= $_; if( length $smallstring > 500_000 ) { push @bigHTML, $smallstring; $smallstring = ''; } } length $smallstring and push @bigHTML, $smallstring; # leftover };