while(){ next unless /(\w+)\.(tiff?)\b/i; print "$1 \t $2\n"; } # or this while(){ next unless my($base, $ext) = /(\w+)\.(tiff?)\b/i; print "$base \t $ext\n"; }