<p>Let&#39;s say you&#39;re building a Perl script to traverse a file system and record what it finds. As you open file handles, you need to know if you&#39;re dealing with an actual file or with a directory, which you treat differently. You want to glob a directory, so you can continue to recursively parse the filesystem. The quickest way to tell files from directories is to use Perl&#39;s built-in <a data-inlink="Hk-kKWG4mOiUGVn6mvdy3g&#61;&#61;" href="https://www.thoughtco.com/telling-if-file-exists-in-perl-2641090" data-component="link" data-source="inlineLink" data-type="internalLink" data-ordinal="1">File Test Operators</a>. Perl has operators you can use to test different aspects of a file. The -f operator is used to identify regular files rather than directories or other types of files.</p><h3>Using the -f File Test Operator</h3><pre> <code> #!/usr/bin/perl -w $filename &#61; &#39;/path/to/your/file.doc&#39;; $directoryname &#61; &#39;/path/to/your/directory&#39;; if (-f $filename) { print &#34;This is a file.&#34;; } if (-d $directoryname) { print &#34;This is a directory.&#34;; } </code></pre><p>First, you create <a data-inlink="UMeALayQ1aE3M6RQPJMr9g&#61;&#61;" href="https://www.thoughtco.com/string-types-in-delphi-delphi-for-beginners-4092544" data-component="link" data-source="inlineLink" data-type="internalLink" data-ordinal="2">two strings</a>: one pointing at a file and one pointing at a directory. Next, test the <strong>$filename</strong> with the <strong>-f</strong> operator, which checks to see if something is a file. This will print &#34;This is a file.&#34; If you try the -f operator on the directory, it doesn&#39;t print. Then, do the opposite for the <strong>$directoryname</strong> and confirm that it is, in fact, a directory. Combine this with <a href="https://www.thoughtco.com/globbing-a-directory-2641092" data-component="link" data-source="inlineLink" data-type="internalLink" data-ordinal="3">a directory glob</a> to sort out which elements are files and which are directories:</p><pre> <code> #!/usr/bin/perl -w &#64;files &#61; &lt;*&gt;; foreach $file (&#64;files) { if (-f $file) { print &#34;This is a file: &#34; . $file; } if (-d $file) { print &#34;This is a directory: &#34; . $file; } }</code></pre><p>A complete list of Perl <a href="https://users.cs.cf.ac.uk/Dave.Marshall/PERL/node69.html#tab:fileop" data-component="link" data-source="inlineLink" data-type="externalLink" data-ordinal="4" rel="nofollow">File Test Operators</a> is available online.</p>