Your code will match only files named with one single digit (i.e "4" or "7")
because you match the beginning of the string with ^, then one digit with \d
and then the end of a string with $.
If you just want the number then use
($imgNumber =~ /^(\d+)/);
if you want the whole name of the file without the extention use
($imgNumber =~ /^(\d+.+)\.jpg/);
if you want something else be more precise in your question ;-)
si_lence