in reply to Searching and Replacing

Hi again, since I didn't know how to edit my top post and didn't want to start a new thread, I will update here. Well part of my program works. The replacement string works but it doesn't preserve the capitalizations from the original text. For example: This is what it currently does:
User Input: She sells Seashells by the seashore. Search Pattern: sea Replacement Pattern: bay Final Output: She sells bayshells by the bayshore. But what I want it to do is keep the capitalization. Final Output: She sells Bayshells by the bayshore.
I don't really know where to begin on this. All I know is that I am not suppose to use arrays or hashes and I'm suppose to convert all the User Input into a lower case copy and work from there. I know some of the functions I am allowed to use are index, substr, length, rindex, lc, lcfirst. Since I can't really expect answers without trying, here's the algorithim I thought up but don't know how to implement. Let's say User input is stored in $input Then I make a lower case copy of $input and call it $lcinput When the user enters the search pattern $pattern and we make it also all lower case. So the program searches for $pattern in $lcinput, when it finds it, index should get the position of the pattern in $lcinput and compare it to that position on $input. If the strings are equal then it just inserts the replacement pattern $replace into both positions in $lcinput and $input to keep the string lengths the same. If the string compare returns that at a certain position the words are unequal then we know there's a capitalization in $input and we modify $replacement to be capitalize. After it goes through the whole length of $lcinput, then we know that we've indirectly gone through $input also. Thus we are done and we print $input and that should be the correct output. I'm sure there is some faulty thinking in there somewhere. But if anyone can point me towards a direction or where to look so i can reference without hashes, arrays, slices, list, and so forth let me know. Here's what I have:
main(); sub main { print "Text to be analyzed.\n"; print "Type a blank line when finished.\n\n"; while (<>) { /^$/&& last; $input.=$_} chomp($input); replace (); $input = ""; again (); } sub replace { print "\nSearched for: "; $pattern = <>; chomp($pattern); print "\nReplace with: "; $replacement = <>; chomp($replacement); $input =~ s/$pattern/$replacement/ig; }