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


in reply to How can I write a function's output to a scalar?

The question is a bit vague, I assume you mean to do something like this:
#!/usr/bin/perl -w use strict; my ($num1,$num2); $num1=2; $num2=sum($num1,$num1); print "$num2\n"; # Sum: returns the sum of all arguments. sub sum { my $ret; $ret=0; for(@_){$ret+=$_} return $ret; }
return tells perl what the subroutine should give back when called, so $num2 is given the final value of $ret in the subroutine sum.