in reply to need help on unopened file handle

By the way,
my $channel = 'two'; next unless /$channel/;
should be
my $channel = 'TWO'; next unless /$channel/;
or
my $channel = 'two'; next unless /$channel/i;

Better yet, since $channel contains text and not a regex, you should use
my $channel = 'TWO'; next unless /\Q$channel\E/;
or
my $channel = 'two'; next unless /\Q$channel\E/i;

Also, I wouldn't rely on $1 and $2 to have remained unchanged after calling two methods.