user@linux-mint ~/perl_practice $ more greet_add_sub.pl use strict; use warnings; sub greet_add { my $sum = 0; my @seen; foreach my $num (@_) { $sum += $num; print "Hi $num, you are the first one!!\n" if !@seen; print "Hi $num, Please join (@seen). " if @seen; push @seen, $num; print "You ", scalar @seen , " fine folks add up to: $sum\n" if scalar @seen > 1; } print "Total is: $sum\n"; } my @list = (1..10); greet_add(@list); user@linux-mint ~/perl_practice $ perl greet_add_sub.pl Hi 1, you are the first one!! Hi 2, Please join (1). You 2 fine folks add up to: 3 Hi 3, Please join (1 2). You 3 fine folks add up to: 6 Hi 4, Please join (1 2 3). You 4 fine folks add up to: 10 Hi 5, Please join (1 2 3 4). You 5 fine folks add up to: 15 Hi 6, Please join (1 2 3 4 5). You 6 fine folks add up to: 21 Hi 7, Please join (1 2 3 4 5 6). You 7 fine folks add up to: 28 Hi 8, Please join (1 2 3 4 5 6 7). You 8 fine folks add up to: 36 Hi 9, Please join (1 2 3 4 5 6 7 8). You 9 fine folks add up to: 45 Hi 10, Please join (1 2 3 4 5 6 7 8 9). You 10 fine folks add up to: 55 Total is: 55 user@linux-mint ~/perl_practice $