#!/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"; } } } #### #!/usr/bin/perl -w use strict; my $path = '/Users/mydirectory/Desktop/BioinfDev/SequenceAssemblyProject/KOMP/*'; foreach (glob("$path\*")) { print "$1\n" if (-d and /\/(\d+)_\w*$/); }