$ ls /tmp/foo/
foo10.txt foo11.txt foo15.txt
$ cat ./foo.pl
use warnings;
use strict;
use Cwd;
my $dir = cwd();
chdir '/tmp/foo';
my @files = glob "foo*.txt";
my $b = "";
for (0..$#files) {
my ($a) = $files[$_] =~ m/foo(.*)\.txt/;
$b = $b.",".$a;
}
chdir $dir;
print "$b\n";
Output:
$ perl ./foo.pl
,10,11,15
How do I avoid first comma, just before 10? also please suggest if there is a better logic than this.