in reply to Oh where has my memory gone?

This is completely unrelated to your issue, but these suggestions may be useful in the future:

Use the strictures:

use warnings; use strict;
Amongst other things, this will warn you that
Scalar value @in_items[0] better written as $in_items[0]

chomp can chomp all elements of a list at once, so there is no need to explicitly chomp each one:

chomp (my @in_items = @_);

It is a good practice to check the return value of open, opendir and system.

Avoid using $a and $b since they have special meaning for sort.