in reply to How do I un-map this code?

Because the function is only returning one item from the list there is no reason to iterate through and sort the entire list:

sub _file_containing { my ( $self, $id ) = @_; opendir my $dir, $self->{ update_dir } or return; my $ret; while ( my $file = readdir $dir ) { next if $file !~ /^\d+$/ || $file > $id; $ret = $file if $ret < $file; } return "$self->{update_dir}/$ret"; }