sort {length $columnA <=> length $columnB} #### sort {length $a <=> length $b} #### Global symbol "$columnA" requires explicit package name (did you forget to declare "my $columnA"?) #### print "matches first" if "a (word) in context " =~ m/\b\(word\)\b/; print "matches second" if "a (word) in context " =~ m/\(word\)/; #### print "matches third" if "a (word) in context " =~ m/(?<=\s)\(word\)(?=\s)/; #### print "matches fourth" if "a a in context (word) " =~ m/(?## #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my %dic; while () { chomp; my($columnA, $columnB) = split("\t", $_); $dic{$columnA} = $columnB; } print Dumper \%dic; my $regex = join ( "|", map {quotemeta} sort { length $a <=> length $b } keys %dic ); $regex = qr/(?