#! /usr/bin/perl -w use 5.018; #1123337 my @arr; my @files=("Die2.txt", "Die1.txt", "Die1.bak", ); # assumes that you have code to ID the files # you want and collect them into an array for (@files) { open (my $InFile, '<', $_) or die "cannot open $_, $!"; while (<$InFile>) { my $var = $_; push @arr, $var; } } say @arr;