I would do it using File::Basename to separate the path from the filename. This simplifies the task a little: you just have to extract the number from the filename:
#!/usr/bin/perl -w
use strict;
use File::Basename;
while (<>) {
my ($name, $path, $suffix) = fileparse ($_, ".txt");
$name =~ /\D+(\d+)/;
print "number: $1\n";
}