while () { # not "for"... no need to suck all into memory if (my ($base, $ext) = /(\w+)\.(tiff?)\b/) { # we have a good $base and $ext } }