in reply to Remove newline character from start of string

Note that chomp depends on the current value of $/. I assume here that you want to emulate that behaviour.

As a regex:

$str =~ s{^\Q$/\E}{};

With substr:

if (substr($str, 0, length($/)) eq $/) { substr($str, 0, length($/), ''; }
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Remove newline character from start of string
by Roy Johnson (Monsignor) on May 10, 2010 at 15:29 UTC
    Or somewhat oddly,
    chomp(substr($str, 0, length($/));

    Caution: Contents may have been coded under pressure.