if (grep /.*P.*\.0912\.ama\.gz/, @sourcefiles) { # ... code ... } #### my @matched = grep /.*P.*\.0912\.ama\.gz/, @sourcefiles; if (@matched) { # ... code ... }