Your code did incorporate the code from elTriberium (= vs =~).
However your code DOES NOT include the code from kennethk.
And it certainly does not show the combined effort of elTriberium, kennethk and Marshall.
Look at your code and then at what kennethk had to say. Maybe:
print $1 "\n"; # Your line versus [kennethk]'s line of
print $1, "\n"; # might actually make a difference?
When you say: I think you should have better tried those codes and then got in here., I think that you have made a mistake. My code combined two previous ideas and then added something more and it does run - no doubt about it. I was genuinely trying to help you.