m/.{$width}/ #### substr($someVar,$offSet,$width) #### $text =~ s/(.*)($string_1)(.*)($string_2)(.*)/$1$4$3$2$5/ #taken from recent post if ($text =~ m/^.*(\.txt)$/) #used to see if $text ends in .txt #### $text = s/($string_1)(.*)($string_2)/$3$2$1/ if ($text =~ m/\.txt$/)