#!/usr/bin/perl use strict; use warnings; my $loop_line = "static replace [something] and [another] thing"; my @matches = $loop_line =~/\[(.*)\]/; # Build a list of matches for ( @matches ) { $loop_line =~ s/\Q$_\E/PING/; } print $loop_line, "\n"; __END__ static replace [PING] thing