in reply to Closing program when end of files is reached

If you had expected this to do validation:
$line = $_; $line=~m%(\d+).*%;
... then you would be mistaken. You could try this instead:
($line) = /(\d+)/ or next;

    -- Chip Salzenberg, Free-Floating Agent of Chaos