#!/usr/bin/perl use strict; # glad to see you using strict. Good job! use warnings; # lexical warnings are better the the -w switch, # becuase you can turn them off where appropriate. # Good job using warnings, too. use diagnostics; # diagnostics give verbose explanations of error messages. # It can be very handy when you are just starting out. # You had: open FNAMES," ) ) { chomp ($fname); # Added a semicolon # Regex based approaches: # Does the string start with an "s"? if ( $fname =~ /^s/ ) { $fname =~ s/^s/_S/; # Do the substitution # Do special stuff } # Did we replace a starting 's' with '_S'? if ( $fname =~ s/^s/_S/ ) { # Do special stuff if we did a substitution. } # Using substr() # # Does the string start with an "s"? if ( 's' == substr($fname, 0, 1) ) { substr($fname, 0, 1) = '_S'; # Do the substitution # or substr($fname, 0, 1, '_S'); # Do the substitution # Do special stuff } # Does the string start with an "s"? if ( 's' == substr($fname, 0, 1) ) { substr($fname, 0, 1) = '_S'; # Do the substitution # or substr($fname, 0, 1, '_S'); # Do the substitution # Do special stuff } }