# not tested my $str='P=HierStehtIrgendwas,I=NocheinText'; if( $str=~/P=(.+?),I=(.+?)$/ ) { print "P-VAL = $1\n"; print "I-VAL = $2\n"; }