opendir my $dh, '/path/to/files', or die ...; while( my file = readdir $dh ) { next unless $file =~ m[\.xml$]; # do something with the file } closedir $dh;