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