$content = join("",); # this is better replaced with arturos method # of reading in whole file foreach $k (keys %links) { $content =~ s/$k/$links{$k}/gm; }