#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(pp); $|=1; #turn off buffering to stdout for debugging my %HoH; #{extension}{name} while (my $full_name = ) { next if $full_name =~ /^\./; # skip names beginning with dot my ($name, $ext) = $full_name =~ /([\w.]+)\.(\w+)$/; next unless defined $ext; # skip bare names wihout .extension $HoH{$ext}{$name}=1; } pp \%HoH; foreach my $pdf_file (keys %{$HoH{pdf}}) { if (exists $HoH{epub}{$pdf_file}) { print "do something with $pdf_file.pdf and $pdf_file.epub\n"; } } =prints { doc => { baz => 1 }, epub => { bar => 1, baz => 1, boo => 1 }, pdf => { baz => 1 }, txt => { "baz" => 1, "boo" => 1, "some.long.name" => 1 }, } do something with baz.pdf and baz.epub =cut __DATA__ . .. some.long.name.txt baz.txt baz.epub baz.doc baz.pdf bar.epub boo.epub boo.txt barefile