First attempt 

#!/usr/bin/perl
use Gnome2::Wnck;
$screen = Gnome2::Wnck::Screen->get_default();
$screen->signal_connect(
    active_window_changed => sub {
        print $screen->get_active_window()->get_name();
    }
);
gtk_main();