sub To_header { my( $outfile, $startix, $endix , $words ) = @_; use autodie; open my($outfh), '>', $outfile ; ## or die by autodie for my $ix ( $startix .. $endix ){ print $outfh $words->[ $ix ]; } close $outfh; } To_header( 'hr.txt', 0, $temp[0], \@words );