use strict; use warnings; use 5.012; sub do_stuff { my $file_pattern = shift; #No loop in sight... my $d = glob $file_pattern; if ($d) { say $d; #...so expect 'dir1/f1' } #No loop in sight... my $e = glob $file_pattern; if ($e) { say $e; #...so expect 'dir1/f1' again } } for my $i (1..10) { do_stuff("dir1/f*"); } --output:-- dir1/f1 dir1/f1 dir1/f2 #uh oh dir1/f2 #no no dir1/f1 dir1/f1 dir1/f2 #Darn dir1/f2 #darn darn dir1/f1 dir1/f1 dir1/f2 #But, but...the docs... dir1/f2 #I'm fired?? !$#!#@$!@#!!!! dir1/f1 dir1/f1