use strict; use warnings; use 5.010; #Create some text files: my @fnames = ('test1.txt', 'test2.txt'); for my $fname(@fnames) { open my $OUT, '>', $fname or die "Couldn't open $fname: $!"; for my $num (1 .. 10) { say $OUT "$fname -- $num"; } } #------------------ sub print_error { say 'error'; } #------------------ #Read the text files: FOR: for my $fname('test1.txt', 'test2.txt') { open my $INPUT, '<', $fname or print_error(); while(my $line = <$INPUT>) { print $line; } print "\n"; } --output:-- test1.txt -- 1 test1.txt -- 2 test1.txt -- 3 test1.txt -- 4 test1.txt -- 5 test1.txt -- 6 test1.txt -- 7 test1.txt -- 8 test1.txt -- 9 test1.txt -- 10 test2.txt -- 1 test2.txt -- 2 test2.txt -- 3 test2.txt -- 4 test2.txt -- 5 test2.txt -- 6 test2.txt -- 7 test2.txt -- 8 test2.txt -- 9 test2.txt -- 10 #### open(DB,"<$F") #compare to: open my $INFILE, '<', $fname or die "Couldn't open $fname: $!"