#!/usr/bin/perl -w use Data::Dumper; use strict; my $mydir = 'mysubdir\*'; my @filear = glob($mydir); my %hash = make_hash(@filear); sub make_hash { (local $/)=undef; my (@files,%hash); @files = @_; foreach my $file ( @files ) { open( my $fh, $file ) or next; $hash{$file} = <$file>; # This line gives "unopened filehandle warning" }; return %hash; } print Dumper \%hash; #### $VAR1 = { 'mysubdir\\file1.txt' => undef, 'mysubdir\\file2.txt' => undef };