I prefer the 4-arg substr for this case:
my $firstChar= substr($string,0,1,"");
Because:
- It avoids copying of the string (it simply updates an offset to where the start of the string is -- for more fun with this trick see (tye)Re: Creative use of pack/unpack) -- some day Perl might be smart enough to optimize your code to act the same as my code, but it isn't that smart today
- It lets you save the removed character in a single step