You can use Apple's UI scripting with Mac::Glue.
Experienced users might notice that you need to set the target app to be frontmost, and the method used here is to use Mac::Glue, which you can't do with non-scriptable apps. This should be coming in a future version of Mac::Glue, but until then, you can use various other methods to set the frontmost app. And of course, this is still quite useful for many scriptable apps, since many scriptable apps don't have full scripting support.
my $app = new Mac::Glue 'System Events';
my $safari = new Mac::Glue 'Safari';
menu_item => 'Close Tab',
menu => 'File',
menu_bar_item => 'File',
menu_bar => 1,
process => 'Safari'
Also, you really should have the UI Element Inspector for this. I think it is included with Panther's dev tools, but I am not sure. Regardless, this is the important portion of its output, to create the above script:
<AXMenuItem: "Close Tab">