chomp $line; #### not needed with below ### $line=~s/^\s+//; $line=~s/\s+$//; # this deletes all line ending char's # so the chomp is unnecessary.