{ 'code' => 'YYK', 'expdate' => '2017-01-01', # <<< noticed that this value was found in the hashref XXY 'date' => '2014-02-20', 'product' => 'buc', 'city' => 'MARS' } #### #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data = [ { 'code' => 'XXY', 'expdate' => '2017-01-01', 'date' => '2017-01-30', 'product' => 'cell', 'city' => 'NYK' }, { 'code' => 'YYK', 'expdate' => '2015-05-05', 'date' => '2014-02-20', 'product' => 'buc', 'city' => 'MARS' }, { 'code' => 'RX Issued', 'expdate' => '2019-11-09', 'date' => '2011-03-11', 'product' => 'idx', 'city' => 'BXO' }, ]; my $results = process( $data ); print "\n\n"; print Dumper $results; print "\n\n"; sub process { my $all = shift || return; my $setdate; my $newdate; foreach my $all_item (reverse @{ $all }) { # If XXY is found use the value in the "expdate" to replace the "expdate" value in YYK # First check if XXY is true and store it if ( $all_item->{ code } eq 'XXY' ) { $newdate = $all_item->{expdate}; } if( $all_item->{ code } eq 'YYK') { # Now, set the new date $all_item->{expdate} = $newdate if $newdate; $setdate = $all_item; } } return $setdate; }