http://www.perlmonks.org?node_id=11130136


in reply to substr odd behavior with list arguments

That's because prototype(\&CORE::substr) is $$;$$. It means each argument is evaluated in scalar context, so in the second case @a is interpreted as scalar @a, i.e. the size of the array, which is 2.

Use

my ($offset, $length) = a_subroutine_call_that_returns_offset_and_leng +th(@some_args); substr('abcdefg', $offset, $length);

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]