foreach (@$arry) { my $x = join("\n", @$_); $x =~ s/^${from}$/${to}/mg; @$_ = split("\n", $x); }