#!/usr/bin/perl  -w

use strict;

sub f {  #just so we can look at caller()
    print "in f()\n";
    for (my $depth = 0;$depth < 10;$depth++) {
        my @from = caller($depth); 
        if ($#from < 0) {last} #are we this deep
        print "package: $from[0]\n";
        print "file: $from[1]\n";
        print "line: $from[2]\n";
        if ($depth) { #when top entry, we were called by f()
            print "sub: $from[3]\n";
        }
    }
    print "\n";
}

sub g { 
    f();    #call f, so we can check caller
}

f();
g();

#generates:
# in f()
# package: main
# file: test.pl
# line: 24
#
# in f()
# package: main
# file: test.pl
# line: 21
# package: main
# file: test.pl
# line: 25
# sub: main::g
