# 1. elide manually managed count variable # 2. read current line into an actual variable while(my $line = <$fh_bigfile>) { # 3. let perl manage the count variable for my $i (0..$#inputs) { # 4. wrong sigil, use $...[$i] instead of @...[$i] # 5. explicitely refer to the line to print it # 6. enclose file handle in braces to make it more obvious print {$filehandles[$i]} $line if (/$regex[$i]/../^END_OF_BLOCK/); } }