# Prebuild the RE patterns for efficiency's sake. my @patterns = ( qr(pattern1), qr(pattern2), qr(pattern3), qr(pattern_n) ); # Use paragraph mode in case your pattern spans multiple lines. # This may need to be combined with the /s switch on your # regexp. Since we don't know what the patterns look like, # I'll use this mechanism to be on the safe side. { local $/ = "\n\n"; while ( my $paragraph = ) { $paragraph =~ s/$_/pagingRAC/gs foreach @patterns; print TEMP_OUT $paragraph; } }