Unsolicited advice, but since you're "strictifying" the script, I'd recommend changing
open IN, $filename to
open my $in, '<', $filename (and if you don't use
autodie, then also add
or die("Couldn't open $filename: $!")). A global
FILEHANDLE led to one of the nastiest bugs I've ever debugged. Also the code assumes
$1,
$2, and
$3 were matched, so you might want to add a check on whether they're defined.