$line =~ / ^ (.+?) (?: < (two|three) > )? $ /xs; #### my $pre= $line; my $post= ''; if( $pre =~ s/ \s* < (two|three) > $ //xs ) { $post= $1; }