in reply to foreach - adding newlines?

You should run your program with the warnings and strict pragmas enabled to let perl help you find mistakes.

open (EVENTS_FILE, 't1Vevents.txt');

You should always verify that the file opened correctly:

open EVENTS_FILE, '<', 't1Vevents.txt' or die "Cannot open 't1Vevents. +txt' $!";

@EVENT_ARRAY = <EVENTS_FILE>;

You could chomp your array elements here if you like:

chomp( my @EVENT_ARRAY = <EVENTS_FILE> );
But do you really need to read the whole file into memory?

foreach $event_line (@EVENT_ARRAY) { chomp;
foreach my $event_line ( @EVENT_ARRAY ) { chomp $event_line;
if ($event_line =~ m/\s*d1/i)

The  \s* at the beginning of the pattern is superfluous because it matches zero characters.

@array = (@array,$d1_value,$d2_value);

That is usually, and more efficiently, written as:

push @array, $d1_value, $d2_value;

So, in summary, you want code more like this:

use warnings; use strict; open EVENTS_FILE, '<', 't1Vevents.txt' or die "Cannot open 't1Vevents. +txt' $!"; my ( @array, %values ); while ( <EVENTS_FILE> ) { chomp; if ( /([dD][12])/ ) { $values{ lc $1 } = ( split /:/ )[ 1 ]; } if ( /[dD]4/ ) { push @array, @values{ 'd1', 'd2' }; } } close EVENTS_FILE; print @array;