use warnings; use File::Copy; # The files 't1.txt', 't2.txt', 't3.txt', # 't4.txt', and 't5.txt' all exist in the cwd. for(1..5) { if (copy("t${_}.txt", "u${_}.txt")) { print "copied t${_}.txt to u${_}.txt\n"; } else {print "$_: Copy failed\n"} } __END__ Outputs: copied t1.txt to u1.txt copied t2.txt to u2.txt copied t3.txt to u3.txt copied t4.txt to u4.txt copied t5.txt to u5.txt