use strict; use warnings; my @x = qw ( a b c d e ff ggg hhhh iiii ); my %y; # Tata!!! Here comes the requested line of code: noLoop(); sub noLoop { $y{pop(@x)} = 1; noLoop() if (scalar(@x)); } # btw.: using global vars in subs is usually bad style ;-) print keys(%y), "\n"; exit 0;