my $var = qq{onChange="[document.approveform.command.value='approve'; document.approveform.submit();]" onClick="[if (this.disabled) {alert('some text!');}]"}; my ($onchange,$onclick); if ($var =~ /onChange/) { $var =~ /onChange\=\"\[(,*)\]\"/; $onchange = $1; } if ($var =~ /onClick/) { $var =~ /onClick\=\"\[(.*)\]\"/; $onclick = $1; } Results: >> $onchange = whole $var exept the start >> onChange="[ << and in the end >> ]" << >> $onclick = just the onClick part, just as it should be.