#!/usr/bin/perl use strict; use warnings; my $text = "start \\chapter{hello}\n end\n"; my $patternreadfromfile = ; chomp $patternreadfromfile; my $inpattern = qr/\\chapter\{(.*)\}/; eval "\$text =~ s/$inpattern/$patternreadfromfile/g"; print "$text\n"; __DATA__ -- FOUND $1 --