#!/usr/bin/perl use strict; use warnings; use 5.010; for my $count (0..4) { given ($count) { when (0) { say "Whoa, it's $count" } when (1) { say "Then it becomes $count" } when (2) { say "Then, $count" } when (3) { say "Only to further increase to $count" } when (4) { say "And eventualy stop at $count" } } } #### #!/usr/bin/perl use strict; use warnings; use 5.010; for (0..4) { when (0) { say "Whoa, it's $_" } when (1) { say "Then it becomes $_" } when (2) { say "Then, $_" } when (3) { say "Only to further increase to $_" } when (4) { say "And eventualy stop at $_" } } __END__ #### #!/usr/bin/perl use strict; use warnings; local $\="\n"; for my $count (0..4) { print +([ sub { my $n=shift; "Whoa, it's $n" }, sub { my $n=shift; "Then it becomes $n" }, sub { my $n=shift; "Then, $n" }, sub { my $n=shift; "Only to further increase to $n" }, sub { my $n=shift; "And eventualy stop at $n" } ]->[$count] || sub {} )->($count); } __END__ #### #!/usr/bin/perl use strict; use warnings; local $\="\n"; for my $count (0..4) { print +([ sub () { "Whoa, it's $count" }, sub () { "Then it becomes $count" }, sub () { "Then, $count" }, sub () { "Only to further increase to $count" }, sub () { "And eventualy stop at $count" } ]->[$count] || sub () {} )->(); } __END__