for (grep /.*P.*\.0912\.ama\.gz/, @sourcefiles) { # $_ contains each matching name }