One approach, would be to create the Macro in Excel, then convert it to perl, you could then call it whenever you like. Good references are available like How do I convert a VBA macro to Perl? from Using OLE with Perl. Super Searching should also return many examples of this sort of thing.