if ($file =~ /\.txt$/) # This would break for a directory called dir.txt - see perldoc -f -X