foreach $file (@files){ next unless $file =~ /\.dat$/; # other stuff here... }