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


in reply to can we pass two variable to foreach loop

Adding to the suggestions by BrowserUk, Zaxo and grinder, another possible solution would be to use each_array from List::MoreUtils. It is a bit of overkill for your current case, but it would work well if you generalized your problem to:
foreach my ($x,$y) (@name,@lastname) { do something }
Only that it would be written as:
use List::MoreUtils qw(each_array); ... my $names = each_array(@name, @lastname); while ( my ($x, $y) = $names->() ) { do something }
With each_array, you may create an iterator which is able to loop over more than one array at once. That easy.