use strict; use warnings; use Test::More tests=>2; my $should_match = 1; my $should_not_match = 0; my @cases = ( ['ON_DIE_FILLER/filler_fuse', 'die0_ON_DIE_FILLER_ON_DIE_FILLER_filler_fuse', $should_match, ], ['ON_DIE_FILLER/filler_fuse', 'die0_ON_DIE_FILLER_ON_DIE_FILLER_filler_byte', $should_not_match, ], ); foreach my $case (@cases) { if ($case->[2] == $should_match) { ok( special_match($case->[0], $case->[1]), $case->[1]); } else { ok( !special_match($case->[0], $case->[1]), $case->[1]); } } sub special_match { my ($s1,$s2) = @_; $s1 =~ tr{/}{_}; # fix separator return $s2 =~ m/$s1$/; # $s1 at end of $s2 } OUTPUT: 1..2 ok 1 - die0_ON_DIE_FILLER_ON_DIE_FILLER_filler_fuse ok 2 - die0_ON_DIE_FILLER_ON_DIE_FILLER_filler_byte