#!/usr/local/bin/perl # http://www.tmp.medtronic.com/~jot/perl-class/examples/manny.pl $input = "manny.inp"; open(INPUT,"$input"); while() { chomp; if (/([a-z]+)\s+(.*)/) { $total = &total_loot($2); # Call our subroutine with the numbers print "Listen up $1, you little worm, send me $total dollars before\n"; print "I send Kneecap Manny for you!\n\n"; } #end if } #end while close(INPUT); sub total_loot { local (@mulah,$total,$amt); @mulah = split(/\s+/,$_[0]); foreach $amt (@mulah) { $total += $amt; } return $total; }