in reply to assign array to hash

So I am trying to create a subroutine that either returns an array or a hash.

A subroutine neither returns a hash, nor an array. It returns a list. See perlsub:

The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this. Both call and return lists may contain as many or as few scalar elements as you'd like. (Often a function without an explicit return statement is called a subroutine, but there's really no difference from Perl's perspective.)

You have @ sigils in your regular expression. You need to escape them with a backslash.

So your captures $1, $2 may consist of one or more words, separated by spaces, which you split further in the sub. You can do without that sub, see map and a statement modifier, see perlsyn:

if($currentSentence =~ /<\@> <s> ([\S\s]+) <head>lines?<\/head> ([\S\s +]+) <\/s> <\@>/) { $features{$_}++ for map { split } $1,$2; }
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'