I know I should be using a module for this, but I wanna do it on my own.
Good for you. I'd rewrite:
$string = m/($start)(*)($end)/;
print "$2";
as
$string =~ m/$start(.+?)$end/s;
print $1;
because
- You use =~ for matching, not =
- Anything in brackets gets 'captured' to $1, $2, etc. You don't need to capture $start and $end, so there's no need for brackets round them
- To match a chunk of text that could be anything, I'd use a dot ('any character' when used with /s, otherwise 'any character except a newline') followed by a plus (match that character 1 or more times) followed by a question mark (match as few characters as possible: for more info see Death to Dot Star!)
- /s at the end, to make the dot match the newline character
- To print a variable, just do print $var - it doesn't need quotes round it.
Hope that helps,
andy.