#!/usr/bin/perl use strict; use warnings; use Test::More; # Set up source strings (keys) and expected results (values) my %tests = ( '"abcd\\\\efgh"' => 'abcd\\\\efgh', '"abcd\\""' => 'abcd\\"', '"abcd\\"efgh"' => 'abcd\\"efgh', '"abcd\\\\\\"efgh"' => 'abcd\\\\\\"efgh', '"abcd\\\\i\\"efgh"' => 'abcd\\\\i\\"efgh', '"abcd\\\\"' => 'abcd\\\\' ); # Set the total number of tests to perform plan tests => 3 * keys %tests; while ( my ($test, $exp) = each %tests) { ok ($test =~ /^"((?:[^"\\]|\\["\\])+)"$/, "$test matches"); is ($1, $exp, "\$1 is $exp"); is ($2, undef, '$2 is undefined'); }