The <GLOB> (or glob()) operator, in scalar context, returns one element at a time. And since this is the sameglob(), it retains its state (it knows what to return next). Since glob("foo.bar") returns just one element (and undef the next time to signify the end of the files found) you get the filename the first time, and then undef the next.