#!/usr/bin/perl use strict; use warnings; my %files; my $dir = shift || '.'; opendir DIR,$dir or die "error opeing directory $dir: $!"; while( defined( my $file = readdir DIR ) ){ my $path = "$dir/$file"; next unless -f $path; open my $fh , '<' , $path or do { warn "$file : $! skipping\n"; next }; $files{$file} = []; while(<$fh>){ push @{$files{$file}} , [ split ] } close $fh; } closedir DIR;