my %all_files; foreach my $file (@files) { open(my $fh, "<", $file); my @data = <$fh>; $all_files{$file} = \@data; close($fh); }