foreach (@line_in body) { # quasi-pseudocode if (|(|) { #$1 contains the whole match, # $2 what's in between the quotes # so delete $1 unless $2 matches the pattern s/$1// unless $2 =~ m|/global_nav\w*\.ssi|; } }