I agree that this is inconsistent behavior in the Perl XML:Simple library and we were not aware of this issue - so thanks for pointing it out. I just glanced the documentation for the library, and I think the 'forcearray' option might be a good workaround. You could either have 'forcearray=>1' as default to ensure that nested elements are always arrays. However, this introduces some overhead in the syntax. Another approach would be to only force the REST objects into arrays, i.e. 'mature', 'precursor', 'species'. If you do this, then the syntax used in our code examples should not break:
my $client = REST::Client->new();
# NoAttr : ignore "type" attributes
# KeyAttr : no folding, array elements are by default folded to a hash based on the attributes "name","key","id"
# ForceArray: Force array representation of miRMaid REST objects
my $xs = XML::Simple->new(NoAttr=>1,KeyAttr=>[],ForceArray=>['mature','precursor','species']);
print "### 2A) Getting the mature sequences for hsa-mir-21 precursor\n";
$client->GET('/precursors/hsa-mir-21/matures.xml');
my $matures = $xs->XMLin($client->responseContent())->{'mature'};
foreach my $m (@$matures) { print $m->{'sequence'}."\n" }
print "### 2B) Getting the mature sequences for hsa-mir-1271 precursor\n";
$client->GET('/precursors/hsa-mir-1271/matures.xml');
my $matures = $xs->XMLin($client->responseContent())->{'mature'};
foreach my $m (@$matures) { print $m->{'sequence'}."\n" }