return grep { s/(\Q$dir\E)(\w+)(\.pm)$/$2/g } %$packlist ; or return grep { s/(\Q$dir\E)(\w+?)(\.pm)$/$2/g } %$packlist ;