#!/usr/bin/perl use strict; use warnings; my $path ='/Users/mydirectory/Desktop/BioinfDev/SequenceAssemblyProject/KOMP/'; my @komp_dir = glob("$path\*"); foreach my $entry (@komp_dir) { if (-d $entry ){ if ($entry =~ /\/(\d+)_\w*$/) { print "$1\n"; } } }