I am trying to execute a perl script that processes a small 12 x 2 text file (approx. 260 bytes) and a large .bedgraph file (at least 1.3 MB in size). From these two files, the script outputs a new bedgraph file.

I have ran this script on 3 other .bedgraph files but I try to run it on the rest of them the process keeps getting `Killed`.

It should take about 20 minutes on average for the perl script to run on each of the `.bedgraph` files.

I'm running the perl script on my local machine (not from a server). I'm using a Linux OS Ubuntu 12.04 system 64-bit 4GB RAM. 

Why does my perl script execution keeps getting killed and how can I fix this?

Here's the script:

```
# input file handle
open(my $sizes_fh, '<', 'S_lycopersicum_chromosomes.size') or die $!;

# output file handles
open(my $output, '+>', 'tendaysafterbreaker_output.bedgraph') or die $!;

my @array;

while(<$sizes_fh>){
    chomp;
    my ($chrom1, $size) = split(/\t/, $_);
    @array = (0) x $size;

    open(my $bedgraph_fh, '<', 'Solanum_lycopersicum_tendaysafterbreaker.bedgraph') or die $!;
    while(<$bedgraph_fh>){
        chomp;
        my ($chrom2, $start, $end, $FPKM) = split(/\t/, $_);

        if ($chrom1 eq $chrom2){
            for(my $i = $start; $i < $end; $i++){
                $array[$i] += $FPKM;
            }
        }
    }

    close $bedgraph_fh or warn $!;

    my ($last_start, $last_end) = 0;
    my $last_value = $array[0];

    for (my $i = 1; $i < $#array; $i++){
        my $curr_val = $array[$i];
        my $curr_pos = $i;

        # if the current value is not equal to the last value
        if ($curr_val != $last_value){
            my $last_value = $curr_val;
            print $output "$chrom1\t$last_start\t$last_end\t$last_value\n";
            $last_start = $last_end = $curr_pos;
        } else {
            $last_end = $i;
        }
    }
}

close $sizes_fh or warn $!;

```