Use my $key instead of $k. And also use strict; use warnings; ...
In reply to Re^3: Parse XML with Perl regex by almut in thread Parse XML with Perl regex by ad23