use IO::Dir; if (my $d = new IO::Dir ".") { while (defined($_ = $d->read)) { something($_); } undef $d; }