#fix dir for my $i (@arr){ $i->{dir} = $1 if $i->{path} =~ m{^(.+)/}; }