Er, no because an intermediate list is still being built. I think the fairer comparison would be to assign to an array in the foo subroutine. Of course a readdir and a grep is not at all equivalent to ls <file> which will immediately see that $file exists (or not) and will not do any further searching, in the pure perl code you are going through every directory entry irrespective of whether you have seen the file or not. You will see somewhat similar performance hit if you did `ls $dir | grep $file`
/J\
|