#!/usr/bin/perl use strict; use warnings; # globbing operator will return the next matching file in local dir # and then false when their are no more while (<*.txt>) { print "1. Found text file: $_\n"; } # this syntax is preferred when using variables in the pattern my $pattern = "*.txt"; while( glob($pattern) ) { print "2. Found text file: $_\n"; }