foreach my $block (@_) { open(OUTPUT, "$file$i") or do { warn "Can't open file: $!"; next }; print OUTPUT $block; close OUTPUT; }