#!/usr/bin/perl use strict; use warnings; my $file = 'test.txt'; my $content = do{ local (@ARGV,$/) = $file; <> }; my $orig = '## ---------------------- ## muu\s\d+ ## ----------------------'; my $replace = "## Fisch ## Fleisch"; $content =~ s/$orig/$replace/g; print $content;