foreach my $line ( @story ) { $line =~ s/\[([A-Za-z-]+)\]/Replace($1)/eg; }