use List::Util qw/reduce/; # my ($a,$b)=(0,0); print reduce { $b+=$a } 1..10; #### use warnings; use strict; # my ($a,$b)=(0,0); use List::MoreUtils qw/pairwise/; my @a = (1 .. 5); my @b = (11 .. 15); my @x = pairwise { $a + $b } @a, @b; # returns 12, 14, 16, 18, 20 use Data::Dump; dd \@x; #### my ($a,$b)=(0,0); print sort { $b cmp $a } 1..10; #### Can't use "my $b" in sort comparison at ... line 2. #### use warnings; use strict; our ($a,$b); package Tst; print sort { $b cmp $a } 1..10; #### Use of uninitialized value $b in string comparison (cmp) at /home/lanx/B/PL/PM/ScopeListUtils.pl line 9. Use of uninitialized value $a in string comparison (cmp) at /home/lanx/B/PL/PM/ScopeListUtils.pl line 9. Use of uninitialized value $b in string comparison (cmp) at /home/lanx/B/PL/PM/ScopeListUtils.pl line 9. Use of uninitialized value $a in string comparison (cmp) at /home/lanx/B/PL/PM/ScopeListUtils.pl line 9. ...