in reply to removing a needle from a haystack

You don't need to do a readdir first. You can leave that up to perl, by using:
while( $file = <$id.'*'> ){ do_something( $file ); }

The <> takes care of the filename expansion.

Hope this helps,

Jeroen
"We are not alone"(FZ)

Update:You can read about it in glob and perlop2. The latter makes me realize that you'll be better of with

while( $file = glob "$id*" ){ do_something( $file ); }