By leave it alone I mean that you leave the statistical routine unchanged (as it worked before) in a separate file called 'yourstatisticalroutine.pl' (or whatever name it has now). Execute this script as an external system process by the system command I mentioned then operate on the file to which its output was is redirected. The script you supplied does the opposite: the statistical routine is copy pasted and I see no 'system' command at all. Now your routine tries to get the file name from the argument list of the main program (which is probably empty). If you choose to do it this way the -command bind should look something like this:
in reply to Re^4: Perl tk - How to integrate external scripts
in thread Perl tk - How to integrate external scripts
In this way your get_statistics routine will be called with the argument 'datafile.name'. You should store your data to be analyzed in this file.
$mw-> Button (-text =>'Get Statistics',
-command =>[ \&get_statistics, 'datafile.name' ]