use warnings; use strict; my $start = ' '; my @keys = 1 .. 5; my $output_file = ".xml"; for my $val ( @keys ) { $output_file = $val . $output_file; open my $file_handle, '>:utf8', $output_file or die "Cannot open '$output_file' because: $!"; print $file_handle "$start\n\t\t
\n"; }