<<
iterate all the files corresponding to $pattern starting from $initial_path
use it as an iterator: my $iter = sto_iter("."); while (my $path = $iter->()) { # do stuff }