$regex = ['foo','bar']; $string = 'blah foo blah'; $string =~ s/$regex->[0]/$regex->[1]/;