in reply to Looping the files in directory to combine with a common file

You can use glob with a single directory or File::Find for a directory tree.

#! /usr/bin/perl # use strict; use warnings; use File::Find; foreach (glob('*.txt')) { print "Found $_ using glob\n"; } find(\&wanted, '.'); sub wanted { return unless /\S+\.txt/i; print "Found $_ using File::Find\n"; #Do something with $_ }