in reply to Removing duplicate lines based on a match

In order to capture matches within a regular expression you'll have to give $id list context:
my ( $id ) = $line =~ m/ID No: (\d+)/;

Should solve your problem


Unless I state otherwise, all my code runs with strict and warnings