my $string = "keep this | keep that too | toss this | toss this too"; my ( $this, $that ); ( $this, $that, undef ) = split /\|/, $string, 3;