my $dir = "c:/"; my @AoA = (); #open dir and loop over files opendir DIR, $dir or die $!; while ( my $file = readdir(DIR) ) { #skip directories next if -d "$dir/$file"; #skip files that are not interesting next unless $file =~ /^Afj(.+)/; #check for existence of corresponding file (warn "corresponding file not found: Cfj$1\n"), next unless -e "$dir/Cfj$1"; #add to array push @AoA, [$file, "Cfj$1"]; } closedir DIR;