my $level = 0; while (my @frame = caller($level++)) { # do stuff with the current frame }