my %info; # a better name should be picked foreach ( qw/ file line type codee desc / ) { my ($info{$_}) = $string =~ /<\Q$_\E>([^<]+)/; }