#!/usr/bin/perl use strict; use warnings; open(my $y, "<", "y") or die "y: $!"; my @y = <$y>; close($y); my $index_y = 0; open(my $x, "<", "x") or die "x: $!"; foreach (<$x>) { chomp; open(my $output, ">", "$_") or die "$_: $!"; print $output "$_$y[$index_y]"; close($output); $index_y++; $index_y = 0 if($index_y > $#y); } close($x);