Why do you add /m to your regular expressions? See perlop - /m changes the meaning of $ and ^.
In reply to Re^2: TRIM in Perl? by Corion in thread TRIM in Perl? by peacemaker1820